Hello.

How can I replace the space with a plus? Is there a str_replace in jQuery?

 var blabla='бла бла'; 

at

 var blabla='бла+бла'; 

I do this to insert it into the browser string

 history.pushState(null, null, 'http://' + window.location.host + '/ ' + blabla); 

but it turns out in the browser line instead of% 20 spaces.

Thank.

    1 answer 1

    Well, so can

      var blabla='бла бла'; blabla.replace(" ","+"); // или blabla.replace("/s","+"); // так правильнее, но заменит только один пробел на символ + так что если в строке друг за другом идет более 1 пробела, то нужно по другому заменять 
    • 3
      This will replace all blabla.replace (/ \ s / g, '+'); // Truth is still needed before that - Yura Ivanov
    • Well, yes, well, the question was about one space, I wrote about one, about the rest I would like to at least someone to learn to think and not copy-paste answers. - Artem