Template:First word/doc: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Wikid77
updated, as new optional parameter sep=/ can set the word separator to slash (or any other character); put section "Performance considerations" for expansion depth, etc.
Ookami (talk | contribs)
m 18 revisions imported
 
(11 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
{{high-use|180612}}
{{lua|Module:String}}
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE---->
__NOTOC__
__NOTOC__
=== Usage ===
This template returns the first word of the first parameter. Use {{para|1}} for the first parameter if the string may contain an [[equals sign]] (=). By default, words are delimited by spaces, but the optional parameter {{para|sep}} can set the separator to any character.


Returns the first word of the first parameter. By default, words are delimited by spaces, but optional parameter sep=/ can set the word separator to slash (or any other character). The parameter should ''not'' have leading spaces, unless the word separator, sep, is set to another character.
==Usage==
One parameter (space as separator):
* <code>'''{&#123;{{BASEPAGENAME}}|'''<var>string</var>'''}}'''</code>
* <code>'''{&#123;{{BASEPAGENAME}}|1='''<var>string</var>'''}}'''</code>


=== Examples ===
Two parameters (user-defined character as separator):
* <code>'''{&#123;{{BASEPAGENAME}}|'''<var>string</var>'''|sep='''<var>character</var>'''}}'''</code>
* <code>'''{&#123;{{BASEPAGENAME}}|1='''<var>string</var>'''|sep='''<var>character</var>'''}}'''</code>


* {&#123;first word|Foo bar baz}} → {{first word|Foo bar baz}}
==Examples==
* {&#123;first word|Foo}} → {{first word|Foo}}
* <code>{&#123;{{BASEPAGENAME}}|Foo bar baz}}</code> → {{{{BASEPAGENAME}}|Foo bar baz}}
* {&#123;first word|Foo-bar-baz}} → {{first word|Foo-bar-baz}}
* <code>{&#123;{{BASEPAGENAME}}| Foo bar baz}}</code> → {{{{BASEPAGENAME}}| Foo bar baz}}
* {&#123;first word|Foo-bar-baz|sep=- }} → {{first word|Foo-bar-baz|sep=- }}
* <code>{&#123;{{BASEPAGENAME}}|Foo}}</code> → {{{{BASEPAGENAME}}|Foo}}
* {&#123;first word|34,000,500|sep=, }} → {{first word|34,000,500|sep=, }}
* <code>{&#123;{{BASEPAGENAME}}|Foo-bar-baz}}</code> → {{{{BASEPAGENAME}}|Foo-bar-baz}}
* {&#123;first word|1=len = a+b |sep== }} → {{first word|1=len = a+b |sep== }}
* <code>{&#123;{{BASEPAGENAME}}|Foo-bar-baz|sep=-}}</code> → {{{{BASEPAGENAME}}|Foo-bar-baz|sep=-}}
* {&#123;first word|Hear ye, users |sep=, }} → {{first word|Hear ye, users |sep=, }}
* <code>{&#123;{{BASEPAGENAME}}|34,000,500|sep=,}}</code> → {{{{BASEPAGENAME}}|34,000,500|sep=,}}
* <code>{&#123;{{BASEPAGENAME}}|Hear ye, users|sep=,}}</code> → {{{{BASEPAGENAME}}|Hear ye, users|sep=,}}
* <code>{&#123;{{BASEPAGENAME}}|1=len = a+b|sep==}}</code> → {{{{BASEPAGENAME}}|1=len = a+b|sep==}}


=== Performance considerations ===
==See also==
The template has been optimized to run very quickly, with template expansion depth of 11 levels. The search for the word separator is run only once, with [[Template:Strfind_short]] used to scan the first 25 characters. Performance has been optimized by using [[Template:Strloc_prefix]] to find then extract the first word, else return the whole when not found.
{{String-handling templates |trim}}


=== See also ===
<includeonly>{{Sandbox other||
{{String templates see also}}


<includeonly>
<!----CATEGORIES BELOW THIS LINE, PLEASE:---->
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
[[Category:String manipulation templates]]
[[Category:String manipulation templates]]


[[sl:Predloga:First word]]
}}</includeonly>
</includeonly>

Latest revision as of 13:18, 3 September 2020

This template returns the first word of the first parameter. Use |1= for the first parameter if the string may contain an equals sign (=). By default, words are delimited by spaces, but the optional parameter |sep= can set the separator to any character.

Usage

One parameter (space as separator):

  • {{First word|string}}
  • {{First word|1=string}}

Two parameters (user-defined character as separator):

  • {{First word|string|sep=character}}
  • {{First word|1=string|sep=character}}

Examples

  • {{First word|Foo bar baz}} → Foo
  • {{First word| Foo bar baz}} → Foo
  • {{First word|Foo}} → Foo
  • {{First word|Foo-bar-baz}} → Foo-bar-baz
  • {{First word|Foo-bar-baz|sep=-}} → Foo
  • {{First word|34,000,500|sep=,}} → 34
  • {{First word|Hear ye, users|sep=,}} → Hear ye
  • {{First word|1=len = a+b|sep==}} → len

See also