[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6 Macros for text handling

There are a number of builtins in T4 for manipulating text in various ways, extracting substrings, searching, substituting, and so on.

The length of a string can be calculated by len:

 
\len{string}

which expands to the length of string, as a decimal number.

Searching for substrings is done with index:

 
\index{string}{substring}

which expands to the index of the first occurrence of substring in string. The first character in string has index 0. If substring does not occur in string, index expands to `-1'.

Substrings are extracted with substr:

 
\substr{string}{from}{length}

which 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 an empty string. The starting index of a string is always 0.

Character translation is done with translit:

 
\translit{string}{chars}{replacement}

which expands to string, with each character that occurs in chars translated into the character from replacement with the same index.

Global substitution in a string is done by patsubst:

 
\patsubst{string}{regexp}{replacement}
which searches string for matches of regexp, and substitutes replacement for each match. The syntax for regular expressions is implementation defined. If you are running T4 on the Java 2 Standard Edition version 1.4 or later, T4 uses java.uti.regex package, otherwise, T4 uses GNU regexp library.

Searching for regular expressions is done with the builtin regexp:

 
\regexp{string}{regexp}

which searches for regexp in string. The syntax for regular expressions is implementation defined. If you are running T4 on the Java 2 Standard Edition version 1.4 or later, T4 uses java.uti.regex package, otherwise, T4 uses GNU regexp library.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on February, 23 2003 using texi2html