Dust-motes

HELPERS / STRINGS

substr

{@substr str=string begin=b end=e len=l /}

Output a substring of a string

Parameters:

  • str : Original string
  • begin : Optional parameter specifying starting character postion. If omitted, it defaults to 0.
  • end : Parameter specifying ending character postion.
  • len : Parameter specifying length of substring.

You can use begin with either end or len. If both are present, len is used. If len is present, str.substr(begin, len) is used to determine the result and the semantics of JavaScript substr apply. If end is present, str.slice(begin, end) is used to determine the result and the semantics of JavaScript slice apply. If both end and len are omitted, you get the whole string as the result.

Examples:


{@substr str="abcdefg" begin="0" end="3"/}
  Output: abc

{@substr str="abcdefg" begin="1" len="4"/}
  Output: bcde