Version 7 of string map

Updated 2002-10-31 12:33:27

Read the information regarding string for the real details of this subcommand.

"string map ..." was introduced as one of the Changes in Tcl/Tk 8.1.1.

It provides the ability to translate portions of a string from one value to another.

For instance:

 % string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
 01321221

As you can see, while you cannot use regular expressions to identify the strings to map, if you have a series of translations to perform, using string map means that you make one pass through the string rather than multiples.

[ Regular expressions are the weapon of choice for some people, to the extent that they fail to notice superior RE-free solutions. "string map ..." is worth learning, in the sense that it solves several important problems that are clumsy with REs.]

See Counting characters in a string on how string map is the best performer (again to RS's surprise...) - because it gets byte-compiled since 8.4.