Can anyone point me out how the first if works and the second doesn’t? I’m puzzled why the second if-clause isn’t working. I’d like to get a hint, thanks.
String msg = o.getTweet();
if (msg.indexOf("&") > 0) {
msg = msg.replaceAll("&", "&");// vervangt & door &
}
if (msg.indexOf(""") > 0) {
msg = msg.replaceAll(""", "aa"); //vervangt " door "
}
Because
ZEROis a very valid index. Try this out,Explanation:
The documentation of
String.indexOf(String str)explains that, “if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.” – [link to docs]This can be done as simple as below, as OpenSauce pointed out here.
Useful links:
indexOf()docsreplace()docsreplaceAll()docs