Is there a fast and easy way to convert the URL-Codes (%20 = <space>) to a normal string?
Hello,%20my%20name%20is%20EggDrop => Hello, my name is EggDrop
Sure, use regsub or string map.Kripton wrote:Is there a fast and easy way to convert the URL-Codes (%20 = <space>) to a normal string?
Hello,%20my%20name%20is%20EggDrop => Hello, my name is EggDrop
Code: Select all
% set string "Hello,%20my%20name%20is%20EggDrop"
Hello,%20my%20name%20is%20EggDrop
% regsub -all {%20} $string { } output
4
% puts $output
Hello, my name is EggDrop
% string map {"%20" " "} $string
Hello, my name is EggDropCode: Select all
proc ::ncgi::decode {str} {
# rewrite "+" back to space
# protect \ from quoting another '\'
set str [string map [list + { } "\\" "\\\\"] $str]
# prepare to process all %-escapes
regsub -all -- {%([A-Fa-f0-9][A-Fa-f0-9])} $str {\\u00\1} str
# process \u unicode mapped chars
return [subst -novar -nocommand $str]
}