I am writing Java code to process a string received from a Mainframe that contains special characters that need to be replaced by other special characters, my search characters are §ÄÖÜäüßö@[\]~{¦} and the replacement characters are @[\]{}~¦§ÄÖÜßäöü so if the string has a { in it I need to replace it with ä and example of my input is "0.201322.05.2017LM-R{der Dopp"
My code currently is
String repChar = "§ÄÖÜäüßö@[\\\\]~{¦}@[\\\\]{}~¦§ÄÖÜßäöü";
// Split String and Convert
String repCharin = repChar.substring(0, repChar.length()/2-1);
String repCharout = repChar.substring(repChar.length()/2, repChar.length()-1);
String strblob = new String(utf8ContentIn);
// Convert
for (int j=0; j < repCharin.length();j++) {
strblob = strblob.replace(repCharin.substring(j, 1), repCharout.substring(j, 1));
}
byte [] utf8Content = strblob.getBytes();
But it generates the following error
java.lang.StringIndexOutOfBoundsException at java.lang.String.substring(String.java:1240)
The \\ are escaped characters I only need a single \