Template:First word/doc: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>DePiep
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.
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
 
__NOTOC__
=== Usage ===
=== Usage ===


Returns first word of the first parameter. Words are delimited by spaces only. The parameter should ''not'' have whitespace.
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.


=== Examples ===
=== Examples ===


* {{tlc|first word|Foo bar baz}} → {{first word|Foo bar baz}}
* {&#123;first word|Foo bar baz}} → {{first word|Foo bar baz}}
* {{tlc|first word|Foo}} → {{first word|Foo}}
* {&#123;first word|Foo}} → {{first word|Foo}}
* {{tlc|first word|Foo-bar-baz}} → {{first word|Foo-bar-baz}}
* {&#123;first word|Foo-bar-baz}} → {{first word|Foo-bar-baz}}
* {&#123;first word|Foo-bar-baz|sep=- }} → {{first word|Foo-bar-baz|sep=- }}
* {&#123;first word|34,000,500|sep=, }} → {{first word|34,000,500|sep=, }}
* {&#123;first word|1=len = a+b |sep== }} → {{first word|1=len = a+b |sep== }}
* {&#123;first word|Hear ye, users |sep=, }} → {{first word|Hear ye, users |sep=, }}
 
=== Performance considerations ===
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.


=== See also ===
=== See also ===

Revision as of 22:50, 30 August 2012

Usage

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.

Examples

  • {{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|1=len = a+b |sep== }} → len
  • {{first word|Hear ye, users |sep=, }} → Hear ye

Performance considerations

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.

See also

Template:String templates see also