0 votes
1 view
in Java by (9.2k 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 (19k 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

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 19 in Java by Jake (6.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...