有一个String text
System.out.println(text);
看起来像这样如何使用的replaceAll
So the traveller sat down by the side of that old man,
face to face with the serene sunset;
and all his friends came softly back and stood around him.
另一个String subText
System.out.println(subText);
删除文本的一部分仅仅是上面的字符串的一部分,看起来像这样
So the traveller sat down by the side of that old man,
face to face with the serene sunset;
我需要摆脱这subText
部分text = text.replaceAll(subtext, "");
但这不对文本做任何事情?
当心:String.replaceAll在Java中使用正则表达式。 – luiscubal
它适合我。 (请确保你在子文本中有确切的东西。) –
可能在删除它之前检查子文本是否在字符串中。可能是您的潜台词中的错字。 if(text.contains(subtext)){do stuff} else {print error} – sirFunkenstine