Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Replace/doc: Difference between revisions

Template page
Created page with "{{used in system|in MediaWiki:Titleblacklist-custom-archive}} {{Documentation subpage}} {{Lua|Module:String}} <!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE END OF THIS PAGE----> ===Usage=== <code>{{((}}replace|''string''|''target''|''replacement''|count=''n''{{))}}</code> Returns ''string'' with the first ''n'' occurrences of ''target'' replaced with ''replacement''. Omitting {{code|1=count}} will replace all occurrences. Space counts as a character if placed i..."
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{used in system|in [[MediaWiki:Titleblacklist-custom-archive]]}}
{{wikipedia|page name}}
{{Documentation subpage}}
{{Documentation subpage}}
{{Lua|Module:String}}
{{Lua|Module:String}}
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE END OF THIS PAGE---->
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE END OF THIS PAGE---->
===Usage===
===Usage===
<code>{{((}}replace|''string''|''target''|''replacement''|count=''n''{{))}}</code>
<code>replace|''string''|''target''|''replacement''|count=''n''</code>


Returns ''string'' with the first ''n'' occurrences of ''target'' replaced with ''replacement''. Omitting {{code|1=count}} will replace all occurrences. Space counts as a character if placed in any of the first three parameters.
Returns ''string'' with the first ''n'' occurrences of ''target'' replaced with ''replacement''. Omitting {{code|1=count}} will replace all occurrences. Space counts as a character if placed in any of the first three parameters.
Line 15: Line 15:
* <code><nowiki>{{replace|One-two two-three two-four twotwo-five|-|—}}</nowiki></code> &rarr; {{replace|One-two two-three two-four twotwo-five|-|—}}
* <code><nowiki>{{replace|One-two two-three two-four twotwo-five|-|—}}</nowiki></code> &rarr; {{replace|One-two two-three two-four twotwo-five|-|—}}
* <code><nowiki>{{replace|One-two two-three two-four twotwo-five|- |—}}</nowiki></code> &rarr; {{replace|One-two two-three two-four twotwo-five|- |—}}
* <code><nowiki>{{replace|One-two two-three two-four twotwo-five|- |—}}</nowiki></code> &rarr; {{replace|One-two two-three two-four twotwo-five|- |—}}
===See also===
* {{tl|str rep}}, which replaces only the first occurrence of a string.
* [[mw:Extension:ParserFunctions/String functions##replace]]
{{String-handling templates |IRL}}


<includeonly>{{Sandbox other||
<includeonly>{{Sandbox other||

Latest revision as of 18:11, 9 April 2025

This page uses Creative Commons Licensed content from Wikipedia (view authors).

Usage

replace|string|target|replacement|count=n

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.

Examples

  • {{replace|One two two three two four twotwo five|two|NINE}} → One NINE NINE three NINE four NINENINE five
  • {{replace|One two two three two four twotwo five|two|NINE|count=2}} → One NINE NINE three two four twotwo five
  • {{replace|foo_bar|_| }} → foo bar

Space

  • {{replace|One-two two-three two-four twotwo-five|-|—}} → One—two two—three two—four twotwo—five
  • {{replace|One-two two-three two-four twotwo-five|- |—}} → One-two two-three two-four twotwo-five