Replace multiple double quotes (") with @ in my string.
var myString="Please "like this blog" and comment. Cheers!"
1) myString = myString.replace(/"/g,'@');
Output
Please @like this blog@ and comment. Cheers!
2) myString=myString.replace(/\s+/g, '-').toLowerCase();
Replace multiple spaces (" ") with - & change into lwowercaseString in my string.
Output
please-"like-this-blog"-and-comment.-cheers!
Please take care of below points:
1)Notice the g flag on the RegExp, it will make the replacement globally within the string, if it's not used, only the first occurrence will be replaced, and also, that RegExp will match one or more white-space characters.
2)Please reinitialize the string when you replace.
i.e var string ="a b c";
string = string.replace(/\s+/g,'');
No comments:
Post a Comment