How can I replace it? I've been trying this:
string.replaceFirst(substring, "");
but it's not replacing, and as I am doing a recursive method, it's giving me a StackOverflowException..
Any idea?
String are immutable, which means you cannot change them once they are initialized.
The replaceFirst method creates a new string where the first instance is replaced by your replacement and returns it...the original string is never modified.
You're code should be something like this
string = string.replaceFirst(substring,"")