Date: Thu, 26 Sep 1996 19:32:33 -0800 From: Peter FierlingerSubject: Re: parser string for cgi? >Has anyone written and (is willing to share!) a lingo function to parse a >string of text into one acceptable to tack onto a call to a cgi? (replaces >all blanks with "+", etc... > >i.e. so I can do: > > getNetText "http://www.blah.com/cgi-bin/repo?user=biff+score=" > & parsetexttoCGIstring( field "score" )
on URLEncode theString
set newString to EMPTY
repeat with x = 1 to the number of chars of theString
set theChar = char x of theString
if chartoNum(char x of theString) < 33 OR chartoNum(theChar) > 127 OR
("+=&%") contains theChar then
set newString = newString & Dec2Hex(chartoNum(theChar))
else
set newString = newString & char x of theString
end if
end repeat
return newString
end
on Dec2Hex decNum
set digit1 = decNum/16
set digit2 = decNum - (digit1 * 16)
case digit1 of
10: set digit1 to "A"
11: set digit1 to "B"
12: set digit1 to "C"
13: set digit1 to "D"
14: set digit1 to "E"
15: set digit1 to "F"
end case
case digit2 of
10: set digit2 to "A"
11: set digit2 to "B"
12: set digit2 to "C"
13: set digit2 to "D"
14: set digit2 to "E"
15: set digit2 to "F"
end case
return "%" & digit1 & digit2
end
Here ya go. Lemme know if this works for you.
Peter
Peter Fierlinger email: peter@turntable.com Turntable Media URL: http://www.turntable.com