Template:String replace

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

{{{1}}}

Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:String replace/doc.

Returns string with the first n occurrences of target replaced with replacement. Omitting count will replace all occurrences. Space counts as a character if placed in any of the first three parameters

Usage

{{String replace |1= |2= |3= |count= }}

Or use the shorthand
{{strrep|string|target|replacement[|count=n]}}

Template parameters

ParameterDescriptionDefaultStatus
1stringInput stringemptyrequired
2targetsubstring to findemptyrequired
3replacementtext to replace target string withemptyoptional
countcountif specified, how many occurrences of target to replace with with replacementemptyoptional

Additional information

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

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

Relies on:
Module:String

Example

{{String replace|One two two three twotwo four two five|two|NINE|count=4}}

renders as:

One NINE NINE three NINENINE four two five

Examples

  • {{String replace|123456789|2|0}} → 103456789
  • {{String replace|\d\d\d\d \d\d\d\d \d\d\d\d \d\d\d[\dX]|\|%}} → %d%d%d%d %d%d%d%d %d%d%d%d %d%d%d[%dX]