Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  





2 Parameters  



2.1  Details  





2.2  Equal signs and pipes  





2.3  White space  







3 Examples  





4 See also  














Template:Str rep






Afrikaans
Алтай тил
العربية
Asturianu
Azərbaycanca
تۆرکجه
Basa Bali

 / Bân-lâm-gú
Башҡортса
Беларуская
Беларуская (тарашкевіца)

Bikol Central
Bosanski
Буряад
Català
Чӑвашла
Dansk
Davvisámegiella
Eesti
Эрзянь
Euskara
فارسی
Føroyskt
Galego
گیلکی
/Hak-kâ-ngî

Hausa
Հայերեն
Hrvatski
Ilokano
Ирон
Jawa
Коми
Kurdî
Кыргызча
Лакку
Latviešu
Лезги
ि
Македонски



مازِرونی
Bahasa Melayu
 / Mìng-dĕ̤ng-nḡ
Мокшень


Нохчийн
ି
Oʻzbekcha / ўзбекча

پښتو

Português
Română
Русиньскый
Русский
Scots

Simple English
Slovenščina
کوردی
Српски / srpski
Suomi
Svenska
Tagalog
Taqbaylit
Татарча / tatarça
 


Thuɔŋjäŋ
Тоҷикӣ

Türkçe
Удмурт
Українська
اردو
Vèneto
Tiếng Vit


 

Edit links
 









Template
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
Wikispecies
Wikiquote
Wikiversity
 
















Appearance
   

 





Permanently protected template

From Wikipedia, the free encyclopedia
 


{{{1}}}

Returns a modified copy of a given text, with the first occurrence of a find-string replaced with a replacement-string.

Usage

  • {{Str rep|text...|find-string|replace-string}}
  • {{Str rep| 1=text... | 2=find-string | 3=replace-string }}
  • This is equivalent to {{#invoke:String|replace|source=text...|find-string|replace-string|1}}.

    Parameters

    There are three positional (unnamed) parameters, all required:

    1. the initial text string subject to search and replacement
    2. the find-string to search for in the text
    3. the replacement string: param 3 replaces param 2's first occurrence in param 1.

    Details

    The value of the text parameter may be anything that resolves to a string, such as:

    Equal signs and pipes

    Equal signs in parameter values passed as immediate text either need to be escapedas{{=}}, or you can leave them unescaped and use the built-in numeric names (|1=, |2=, and |3=) for the three unnamed positional parameters, as in the section usage at the top.

    Pipe characters in immediate text should be escaped either as | or as {{!}}. See Help:Template#Hints and workarounds. Pipe characters in embedded items such as params or template invocations don't need to be escaped.

    White space

    Pay attention to the use of white space in the parameters; all white space is significant in positional parameters. In particular, leading and trailing white space is not removed, and can affect the results. See contrasting examples #1 and #2 below.

    If you like the readability of having convenience blanks before and after the parameters so they're not adjacent to the pipe characters, then use the built-in numeric names |1=, etc. These will not include any leading or trailing blanks in the parameter value; see example 3.

    Examples

    1. {{str rep|Dogs chase cats.|cats|balls}} ⟶ Dogs chase balls.
    2. {{str rep|Dogs chase cats.|cats |balls }} ⟶ Dogs chase cats.     — Red X 8pxN leading and trailing blanks are significant; see Details
    3. {{str rep|Dogs chase cats.|2=cats |3=balls }} ⟶ Dogs chase balls.     — Green tickY ... but not when named parameters are used
    4. {{str rep|Dogs chase cats. Cats chase mice.|chase|love}} ⟶ Dogs love cats. Cats chase mice.     — only first occurrence replaced
    5. {{str rep|{{Str rep/doc/Dogs and cats}}|chase|love}} ⟶ Dogs love cats. Cats chase mice.     — text can be entered by a template

    See also


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:Str_rep&oldid=1208350174"

    Categories: 
    Templates based on the String Lua module
    String manipulation templates
    Hidden category: 
    Wikipedia fully protected templates
     



    This page was last edited on 17 February 2024, at 04:59 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki