I'm cleaning an incoming text in my Java code. The text includes a lot of "
", but not as in a new line, but literally "
". I was using replaceAll() from the String class, but haven't been able to delete the "
".
This doesn't seem to work:
String string;
string = string.replaceAll("\n", "");
Neither does this:
String string;
string = string.replaceAll("
", "");
I guess this last one is identified as an actual new line, so all the new lines from the text would be removed.
Also, what would be an effective way to remove different patterns of wrong text from a String. I'm using regular expressions to detect them, stuff like HTML reserved characters, etc. and replaceAll, but everytime I use replaceAll, the whole String is read, right?
UPDATE: Thanks for your great answers. I' ve extended this question here:
Text replacement efficiency
I'm asking specifically about efficiency :D
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…