|
Description:
The split command splits a string based on each character that is in the splitString. This version handles the splitString as a combined string, splitting the string into constituent parts.
Source: Text Source
proc mcsplit "str splitStr {mc {\x00}}" {
return [split [string map [list $splitStr $mc] $str] $mc]
}
The license for this recipe is available here.
Discussion:
This one-line multi-character split is simple and efficient. The splitStr is mapped into the single magic character which can then be passed to split for splitting the string. Be careful to make sure your string does not have NULLs, or to use a different magic character. Perhaps an undefined Unicode character would also be a good default magic character.
|