如何替换子串?

时间:2014-07-10 05:09:49

标签: java

鉴于以下String "ws([WM_10003] , {MD_1402359631813}{MV_200101010000024})"我只需要替换"{MD_1402359631813}" ""这个值如何解决这个问题。如何替换子串?

1 个答案:

答案 0 :(得分:2)

您没有给我们太多帮助,但根据您的问题,我怀疑您忘记更新您的String参考。它就像这样简单,

String str = "ws([WM_10003] , {MD_1402359631813}{MV_200101010000024})";
String toRemove = "{MD_1402359631813}";
System.out.println("Before: " + str);
str = str.replace(toRemove, "");
System.out.println("After: " + str);

输出

Before: ws([WM_10003] , {MD_1402359631813}{MV_200101010000024})
After: ws([WM_10003] , {MV_200101010000024})