Strings are immutable in Java – operations like replace
don’t actually update the original string. You have to use the return value of the substring
call, e.g.
String updated = str.substring(j,str.indexOf('>',j+1)).replaceAll("\n", "#10");
If you want to replace this in the overall string, you can simply concatenate this back into the string:
int indexOf = str.indexOf('>',j+1);
str = str.substring(0, j)
+ str.substring(j,indexOf).replaceAll("\n", "#10"))
+ str.substring(indexOf);
2
solved String parsing, replace new line character