Template:Str right: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
(straight port of wikipedia:template:str right)
 
m (Protected "Template:Str right": If you'd like to suggest changes to this template, please do so at forum:Panopticon. This template is being protected because it impacts many other pages and templates. ([edit=sysop] (indefinite) [move=sysop] (indef)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<includeonly>{{{{{|safesubst:}}}Str sub long|nocategory={{{nocategory|}}}|{{{1}}}|{{{2}}}|{{{{{|safesubst:}}}#expr:{{{{{|safesubst:}}}Str len|nocategory={{{nocategory|}}}|{{{1}}}}}-{{{2}}}}}}}</includeonly><noinclude>
<includeonly>{{{{{|safesubst:}}}Str sub long|nocategory={{{nocategory|}}}|{{{1}}}|{{{2}}}|{{{{{|safesubst:}}}#expr:{{{{{|safesubst:}}}Str len|nocategory={{{nocategory|}}}|{{{1}}}}}-{{{2}}}}}}}</includeonly><noinclude>
{{Documentation}}[[category:coding utility templates]]
{{Documentation}}[[category:string manipulation templates]]
</noinclude>
</noinclude>

Latest revision as of 05:18, 15 May 2012

Instructions for {{Str right}}
{{str right}} is a part of a pair of templates used to truncate characters from a phrase. This one obviously handles the right side of a string; {{str left}} chops of characters from the left side.

Usage

{{Str right|<string>|<offset>}}

Gives the characters from <offset> to the end of the string.

A negative <offset> is treated the same as zero, which simply returns the original string.

If <offset> is longer than <string> then this returns an empty string.

If <offset> 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.

Examples

  • {{Str right| lorem ipsum dolor sit amet | 10 }} → m dolor sit amet
  • {{Str right| lorem ipsum dolor sit amet | 1 }} → orem ipsum dolor sit amet
  • {{Str right| lorem ipsum dolor sit amet | 0 }} → lorem ipsum dolor sit amet
  • {{Str right |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