开发者

Special character checking in JavaScript

I have a string:

var string = "asdasASFASDŞGFSD123435489()/%&&&&&&&&&&&&&&&123435";

I want this string to have a space after any group of ampersands. So in this example, I开发者_JAVA百科 want the output:

"asdasASFASDŞGFSD123435489()/%&&&&&&&&&&&&&&& 123435";

How can I accomplish this in JavaScript?


well, mine is cooler ;)

 var string = "asdasASFASDŞGFSD123435489()/%&&&&&&&&&&&&&&&123435";
 alert(string.replace(/&+/g, "$& "))


I think this is the job of regular expressions. For example you could do something like this (not tested, just to get the idea):

string.replace("(&+)", "$1 ");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜