Click to See Complete Forum and Search --> : changing %20 in a string to a space
drn33
02-20-2003, 12:07 PM
Hi, I'm sure this question has been asked 1000 times, but I was not able to find a good thread. I am passing a string in the URL from one page to another. I am able to parse out the string, but do not know how to change the %20 into a space in my string. Can someone please help me solve this?
Thanks, Darren
Charles
02-20-2003, 12:15 PM
Use the unescape() function and see http://developer.netscape.com/docs/manuals/js/client/jsref/toplev.htm#1064583.
drn33
02-20-2003, 12:22 PM
Thanks Charles for the info and the link. I looked up the unescape function and thought it need an escape function first. Is this true? I am passing simple text through the url and extracting the text I need on the next page using a substr command. So all I really need to do is change that string, currently "Indonesian%20Coconut%20Pots" to "Indonesian Coconut Pots".
Thanks again, Darren
Charles
02-20-2003, 12:32 PM
The unescape() function doesn't know or care if the escape() has first been called. But if you have some other things in there that might look like escaped characters and that you don't want unescaped then use:
'Indonesian%20Coconut%20Pots'.replace(/%20/g, ' ')
And you might find the using RegExp objects and methods is an easier way to extract your information. See http://developer.netscape.com/docs/manuals/js/client/jsref/regexp.htm.
drn33
02-20-2003, 12:59 PM
Thanks again for the response. I was unable to make the unescape string work. Where would I put it in the code below?
<SCRIPT LANGUAGE="javascript">
var locate = window.location
document.form1.var1.value = locate
var text = document.form1.var1.value
function delineate(str)
{
theleft = str.indexOf("&") + 1;
theright = str.indexOf("!");
return(str.substring(theleft, theright));
}
var newimage = delineate(text)
<!-- here's where I need to remove the %20
document.write(delineate(text));
</SCRIPT>
Any ideas? I will look into the RegExp example you gave me as well.
Thanks, Darren
Charles
02-20-2003, 03:41 PM
document.write(unescape(delineate(text)));
drn33
02-20-2003, 11:28 PM
That worked perfectly! Thank you very much Charles.