faqts : Computers : Programming : Languages : JavaScript : Language Core : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 29 people (83%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

in my string, how do i replace spaces and other characters so that a proper URL is formed?

Jul 12th, 2001 23:47
Joe Lipman, tristian o\'brien,


To encode any string for use in a URL, try using the escape() method

theEncodedURL = escape(theString);

Spaces will be replaced with %20.  Plus symbols are exempt however the 
code

theEncodedURL = escape(theString, 1);

is supposed to work.

To reverse the command, try the unescape() method

theDecodedURL = unescape(theEncodedURL);