www.delorie.com/gnu/docs/m4/m4_55.html   search  
 
Buy GNU books!


GNU macro processor

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

10.5 Translating characters

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.

If replacement is shorter than chars, the excess characters are deleted from the expansion. If replacement is omitted, all characters in string, that are present in chars are deleted from the expansion.

Both chars and replacement can contain character-ranges, e.g., `a-z' (meaning all lowercase letters) or `0-9' (meaning all digits). To include a dash `-' in chars or replacement, place it first or last.

It is not an error for the last character in the range to be `larger' than the first. In that case, the range runs backwards, i.e., `9-0' means the string `9876543210'.

 
translit(`GNUs not Unix', `A-Z')
=>s not nix
translit(`GNUs not Unix', `a-z', `A-Z')
=>GNUS NOT UNIX
translit(`GNUs not Unix', `A-Z', `z-a')
=>tmfs not fnix

The first example deletes all uppercase letters, the second converts lowercase to uppercase, and the third `mirrors' all uppercase letters, while converting them to lowercase. The two first cases are by far the most common.

The builtin macro translit is recognized only when given arguments.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003