views:

92

answers:

2

I'm grabbing the query string parameters and trying to do this:

var hello = unescape(helloQueryString); 

and it returns:

this+is+the+string

instead of:

this is the string

Works great if %20's were in there, but it's +'s. Any way to decode these properly so they + signs move to be spaces?

Thanks.

A: 

Adding this line after would work:

hello = hello.replace( '+', ' ' );
Kerry
hello = hello.replace(/\+/g, ' ') if you anticipate more spaces between words.
Murali VP
Wouldn't it be better to do (this way you don't get giant gaps of spaces): hello.replace(/\++/, '')
Kerry
+2  A: 

The decodeURIComponent function will handle correctly the decoding:

decodeURIComponent("this%20is%20the%20string"); // "this is the string"

Give a look to the following article:

CMS