Javascript replace query string + space

I grab the query string parameters and try to do this:

var hello = unescape(helloQueryString); 

and it returns:

 this+is+the+string 

instead:

 this is the string 

Works great if there was% 20, but that's +. Any way to decode them correctly so that they + characters move to spaces?

Thanks.

+4
source share
2 answers

The decodeURIComponent function correctly processes decoding:

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

Take a look at the following article:

+7
source

Adding this line after work:

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

Source: https://habr.com/ru/post/1311044/


All Articles