Template:Str rep

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:Str rep/doc.

Returns string0 with the *first* occurrence of string1 replaced with string2. Note that while the first two parameters are marked required, the template technically works even without supplying them, but simply returns string0 in this case.

Usage

{{Str rep |1= |2= |3= }}

Template parameters

<templatedata>JSON</templatedata> ./. {{TemplateBox}}
TemplateData

TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.


Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template. ‎<nowiki>-tags can be wrapped around the arguments, if required, to avoid templates being expanded.

Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw ‎<templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.

Discussion
There is an ongoing discussion about that matter. Feel invited to comment if you are experienced in either way, your time permits and if you like to share your opinion or to make a suggestion.


Wikipedia's help about TemplateDataCommons-specific information

Returns string0 with the *first* occurrence of string1 replaced with string2. Note that while the first two parameters are marked required, the template technically works even without supplying them, but simply returns string0 in this case.

Template parameters[Edit template data]

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
string01

The text to replace in

Unknownrequired
string12

The text to search for

Unknownrequired
string23

The text to replace with

Unknownoptional

Additional information

The template is intended to be used in the following namespaces: the Template namespace

The template is intended to be used by the following user groups: all users

Relies on:
Module:String

Example

{{Str rep|032|3|1}}

renders as:

012

See also

Trimming templates:

  • {{Trunc}} – To trim down to a specified number of characters.
  • {{Trim}} — To trim any leading or trailing whitespace.
  • {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
  • {{Str right}}

Analyzing templates:

  • {{Str endswith}} – To check if a string ends with a given string.
  • {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
  • {{Str len}} – Returns a string's length. Can count up to 500 characters.

String length comparison templates:

  • {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.

Sandboxes and test cases:

Technical stuff:

Localization

This template is not intended to be localized.