Difference between revisions of "Template:Str index/doc"

From Ava Zinn Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
(Fix link)
m (32 revisions from wikipedia:Template:Str index/doc)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{Documentation subpage}}
 
{{Documentation subpage}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
+
{{Lua|Module:String}}
 +
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE---->
 +
===Usage===
 +
<nowiki>{{str index|</nowiki>''text''|''number''<nowiki>}}</nowiki> = Returns the ''number''-th character of ''text''.
  
=== Usage ===
+
Base 1: the first character is numbered 1, and so on.  Any leading or trailing whitespace is removed from the string before searching.
<nowiki>{{str index|</nowiki>''text''|''number''<nowiki>}}</nowiki> = Returns the ''number''-th character of ''text''. Base 1: the first character is numbered 1, and so on.
 
  
Only supports a limited character setReturns an error on unknown characters. Returns &amp;#32; for a blank space.
+
If the requested position is negative, this function will search the string counting from the last character.  In other words,
 +
number = -1 is the same as asking for the last character of the string.
  
:{{Str character set documentation}}
+
A requested position equal to zero or with a value longer than the string will generate an error.
  
=== Examples ===
+
This function will properly return a space character (' ') if the selected position contains a space.
 +
 
 +
===Examples===
 
* <code>{{tlp|str index|0123456789ABCDEF|15}}</code> → {{str index|0123456789ABCDEF|15}}
 
* <code>{{tlp|str index|0123456789ABCDEF|15}}</code> → {{str index|0123456789ABCDEF|15}}
 
* <code>{{tlp|str index|0123456789ABCDEF|18}}</code> → {{str index|0123456789ABCDEF|18 |nocategory=true}}
 
* <code>{{tlp|str index|0123456789ABCDEF|18}}</code> → {{str index|0123456789ABCDEF|18 |nocategory=true}}
* <code><nowiki>{{str len|{{str index|a b|2}}}}}}</nowiki></code> → {{str len|{{str index|a b|2}}}} (because the return is <code>&amp;#32;</code> rather than a space character.)
 
  
=== See also ===
+
===See also===
{{String templates see also}}
+
{{String-handling templates |trim}}
 +
 
 
<includeonly>
 
<includeonly>
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
+
<!----CATEGORIES BELOW THIS LINE, PLEASE:---->
 +
{{#ifeq:{{SUBPAGENAME}}|sandbox | |
 
[[Category:String manipulation templates]]
 
[[Category:String manipulation templates]]
 
+
}}
[[bg:Шаблон:Str index]]
 
[[de:Vorlage:Str index]]
 
[[es:Plantilla:Str index]]
 
[[id:Templat:Str index]]
 
[[ja:Template:Str index]]
 
[[ko:틀:Str index]]
 
[[pt:Predefinição:Str index]]
 
[[ru:Шаблон:Str index]]
 
[[sco:Template:Str index]]
 
[[sl:Predloga:Str index]]
 
 
</includeonly>
 
</includeonly>

Latest revision as of 01:56, 7 March 2016

Gnome-utilities-terminal.svg This template uses (or will be using) Lua programming language.

Please see Wikipedia:Lua if you want to learn more about Lua or help convert other templates.

Usage[edit]

{{str index|text|number}} = Returns the number-th character of text.

Base 1: the first character is numbered 1, and so on. Any leading or trailing whitespace is removed from the string before searching.

If the requested position is negative, this function will search the string counting from the last character. In other words, number = -1 is the same as asking for the last character of the string.

A requested position equal to zero or with a value longer than the string will generate an error.

This function will properly return a space character (' ') if the selected position contains a space.

Examples[edit]

  • {{str index|0123456789ABCDEF|15}}Character not recognized by string_index
  • {{str index|0123456789ABCDEF|18}}((str index)): String is not long enough.

See also[edit]