This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Converting URL-Codes

Old posts that have not been replied to for several years.
Locked
K
Kripton
Voice
Posts: 28
Joined: Tue Jan 06, 2004 6:54 am

Converting URL-Codes

Post by Kripton »

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
d
dollar
Op
Posts: 178
Joined: Tue Oct 28, 2003 3:47 pm
Location: Netherlands

Re: Converting URL-Codes

Post by dollar »

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
Sure, use regsub or string map.

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 EggDrop
dollar (or something similar) at:
#eggdrop / #tcl - undernet
#egghelp / #tcl / #eggtcl - efnet
#eggdrop.support / #tcl - quakenet
#eggdrop - ircnet
K
Kripton
Voice
Posts: 28
Joined: Tue Jan 06, 2004 6:54 am

Post by Kripton »

yes, thank ya!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Alternatly, use some proper code to do it. They will only convert the specific chars you tell it to, this function/procedure will convert all the required stuff in the text.

Code: 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]
}
This was taken from the ncgi library available with tcllib.
K
Kripton
Voice
Posts: 28
Joined: Tue Jan 06, 2004 6:54 am

Post by Kripton »

Ok, sounds better! Thanx!
Locked