开发者

How do I replace a substring that appears more than once in a string?

I am curious on how to replace all the开发者_开发问答 instances of '(A)' in a string with just 'A'.

This is what I have, but it is not working:

String str = "(A) + (B) + ( (A) + (B) )";
str = str.replace("(A)","A");

Thanks, Y_Y


I think you have do do it in a loop, that is:

while(str.indexOf(pattern) != -1) str.replace(pattern, replacement);

Look at adobe's documentation, too. It usually knows the answer. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜