But also, your first "substring" statement is wrong.
As you have it - substring (0) - it simply returns the whole string, you need a
second parameter to define the length of the substring. In your case, that'll
be "index" or "index - 1" I would think.
BTW If you want this code to be efficient, you should look at the "replaceAll"
method which will do what you want much faster, I'd think. If it's just a
programming exercise, your approach is fine.