We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I need to eliminate some words from a text. Here is my code:
StringList rawstring;
rawstring = new StringList();
String[] passerstring = loadStrings("NovumOrganum.txt");
String[] stopwords = loadStrings("stopwords.txt");
String[] romans = loadStrings("roman.txt" );
rawstring.append(passerstring);
String comp1 = rawstring.get(19 ); //Equals "I".
String comp2 = romans[0]; //Equals "I".
comp1.replaceAll("\n", ""); // I thought carriage returns may have been
comp1.replaceAll("\r", ""); // the problem, but this didn't work.
comp2.replaceAll("\n", "");
comp2.replaceAll("\r", "");
println(comp1.equals(comp2)); //Prints "false".
println(comp1); //Prints "I".
println(comp2); // Prints "I".
What do I need to do? Please help. :(
Answers
Ok, I got it. I used
comp2 = comp2.replaceAll("\\s+", "");
:)
what is \s pls?
It's RegEx related! Still need to learn that! 8-|
Take a look @ Pattern class to have an idea:
http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
More precisely, \s+ means "any space character (including newlines); at least one (or more)".