I am using the string.replaceFirst() method in order to replace the first instance of <text>
with another string. I used the indexOf method to search for both brackets, and then the replaceFirst method. It works perfectly if text
is replaced with any string with an alphanumeric character at the end, but fails to replace when I do something like <some string$>
. For reference, the method is
public static String substituteWord(String original, String word) {
int index1 = original.indexOf("<");
int index2 = original.indexOf(">");
storyLine = original.replaceFirst(original.substring(index1,index2+1), word);
return original;
}
The code doesn't look broken, but why does using a dollar sign make this method fail?