Template:Chr

From Australian sf information
Revision as of 18:42, 24 January 2011 by Thomas Bull (talk | contribs) (copy/paste from Wikipedia)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Usage

{{Chr|text|n}} = Returns the n-th character of text.

Supports a larger character set, allowing the text to have accented letters. Returns an error message for unknown characters.

Examples

  • {{ Chr |0123456789ABCDEF|15}}Template:P1
  • {{ Chr |ÁBĆĎÉf-ABCDEF|4}}Template:P1
  • {{ Str len |{{ Chr |a b|1}}}} → 16
  • {{ Str len |{{ Chr |a b|2}}}} → 16
  • {{ Str len |{{ Chr |a b|3}}}} → 16

The last example shows extraction of letter "b" with string length as 1. The prior example extracts a blank but considers the length as 0, for there are no characters. If surrounded by 2 other characters, then the length would be totalled as 3 characters:

  • {{ Str len |<{{ Chr |a b|2}}>}} → 18
  • {{ Str len |X{{ Chr |a b|2}}X}} → 18
  • {{ Str len |X{{ Str index any |a b|2}}X}} → 29
  • X{{ Chr |a b|2}}X → XTemplate:P1X

A string-length problem occurs when using template {{ Str index any }}.