BruceClark
BruceClark

Reputation: 41

Javascript replace query string + with a space

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.

Upvotes: 4

Views: 18528

Answers (2)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827822

The decodeURIComponent function will handle correctly the decoding:

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

Give a look to the following article:

Upvotes: 10

Kerry Jones
Kerry Jones

Reputation: 21848

Adding this line after would work:

hello = hello.replace( '+', ' ' );

Upvotes: 0

Related Questions