4

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.

2 Answers 2

10

The decodeURIComponent function will handle correctly the decoding:

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

Give a look to the following article:

Sign up to request clarification or add additional context in comments.

1 Comment

the question is specifically asking about strings with + instead of %20
0

Adding this line after would work:

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

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.