开发者

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

开发者 https://www.devze.com 2023-03-12 08:00 出处:网络
I am curious on how to replace all the开发者_开发问答 instances of \'(A)\' in a string with just \'A\'.

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

精彩评论

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