Created
November 14, 2021 13:11
-
-
Save nat-418/7f08d63a9e1772be2e81846a0d9ab1ab to your computer and use it in GitHub Desktop.
Replace whitespace characters with escape codes in Tcl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Replace whitespace characters with their escape codes | |
# | |
# @param str String containing some whitespace | |
# @return New string with escapes instead of whitespace | |
proc space2escape str { | |
set escapes { | |
\b \\b | |
\f \\f | |
\n \\n | |
\r \\r | |
\t \\t | |
} | |
return [string map $escapes $str] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment