Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the code I’ve which replaces the multiple spaces with ‘+’. 

var str = 'a b c';

var replaced = str.replace(' ', '+');

It works only for the first occurrence. Can anyone tell me how to replace it for all?

1 Answer

0 votes
by (19.7k points)

Check the code below:

var str = 'a b c';

var replaced = str.split(' ').join('+');

Interested in Java? Check out this Java Certification by Intellipaat. 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...