Next: Translit Prev: Regexp Up: Text handling

11.4 Extracting substrings

Substrings are extracted with `substr':

 -- Builtin: substr (STRING, FROM, [LENGTH])
     Expands to the substring of STRING, which starts at index FROM,
     and extends for LENGTH characters, or to the end of STRING, if
     LENGTH is omitted.  The starting index of a string is always 0.
     The expansion is empty if there is an error parsing FROM or
     LENGTH, if FROM is beyond the end of STRING, or if LENGTH is

     The macro `substr' is recognized only with parameters.

     substr(`gnus, gnats, and armadillos', `6')
     =>gnats, and armadillos
     substr(`gnus, gnats, and armadillos', `6', `5')

   Omitting FROM evokes a warning, but still produces output.

     error-->m4:stdin:1: Warning: too few arguments to builtin `substr'
     error-->m4:stdin:2: empty string treated as 0 in builtin `substr'

automatically generated by info2www