Can someone tell me how the first if it works, and the second not? I am puzzled why the second if-clause is not working. I would like a tip, 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 it ZEROis a very valid index. Try it,
ZERO
String msg = o.getTweet(); if (msg.indexOf("&") != -1) { msg = msg.replaceAll("&", "&");// vervangt & door & } if (msg.indexOf(""") != -1) { msg = msg.replaceAll(""", "aa"); //vervangt " door " }
Explanation:
The documentation String.indexOf(String str)explains that "if a string argument occurs as a substring inside 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". - [link to documents]
String.indexOf(String str)
, : OpenSauce .
msg = msg.replace("&", "&").replace(""", "\"");
:
indexOf()
replace()
replaceAll()
, , replace replaceAll , . , replace replaceAll - , , .
replace
replaceAll
, replace , . replace replaceAll , arg .