Skip to content

Instantly share code, notes, and snippets.

@nat-418
Created November 14, 2021 13:11
Show Gist options
  • Save nat-418/7f08d63a9e1772be2e81846a0d9ab1ab to your computer and use it in GitHub Desktop.
Save nat-418/7f08d63a9e1772be2e81846a0d9ab1ab to your computer and use it in GitHub Desktop.
Replace whitespace characters with escape codes in Tcl
# 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