Template:Str rightc/doc: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
 
m (Bot: Adding <noinclude>{{PAGENAME}}</noinclude>)
Line 1: Line 1:
: <code>{{Tlx|Str rightc|<string>|<count>}}</code>
: <code>{{Tlx|Str rightc|<string>|<count>}}</code>
: <code>{{Tlx|Str rightc|<string>|<count>|<result if empty>}}</code>
: <code>{{Tlx|Str rightc|<string>|<count>|<result if empty>}}</code>
Line 20: Line 19:
*<tt><nowiki>{{Str rightc| | 1 | empty }}</nowiki></tt> &rarr; {{Str rightc| | 1 |empty }}
*<tt><nowiki>{{Str rightc| | 1 | empty }}</nowiki></tt> &rarr; {{Str rightc| | 1 |empty }}
*<tt><nowiki>{{Str rightc |123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1 | 99}}</nowiki></tt> &rarr; {{Str rightc |nocategory=true |123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1 | 99}}
*<tt><nowiki>{{Str rightc |123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1 | 99}}</nowiki></tt> &rarr; {{Str rightc |nocategory=true |123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1 | 99}}
<noinclude>[[category:template documentation|{{PAGENAME}}]]</noinclude>

Revision as of 14:04, 18 May 2012

{{Str rightc|<string>|<count>}}
{{Str rightc|<string>|<count>|<result if empty>}}

Gives a substring of length <count> of characters from the right-side end of the string. If the parameter 1 <string> is empty, then immediately returns with parameter 3 (or nothing), and skips all the complex processing usually needed to extract a substring.

If <count> is invalid, empty or undefined, this template goes berserk, so don't do that.

Limitations

  • Up to 100 chararacters in the input string. If possible, first check length of input string using {{Str len}}. Using strings longer than 100 characters may result in the error "max index is 100 for str_sub".
  • Limited set of characters.
  • Expensive (if used too many times per page, generates "Wikimedia Foundation Server Error").
  • Returning parameter 3, when parameter 1 is empty, was added 8 May 2010.

Examples

  • {{Str rightc| lorem ipsum dolor sit amet | 10 }} → r sit amet
  • {{Str rightc| lorem ipsum dolor sit amet | 1 }} → t
  • {{Str rightc| lorem ipsum dolor sit amet | 0 }}
  • {{Str rightc| | 1 | empty }} → empty
  • {{Str rightc |123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1 | 99}} → 3456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.max index is 100 for str sub long