I want to remove last occurrence of "\" this special character from my string.
I tried it with string functions like
String word = str.substring(str.lastIndexOf("\"));
You need to use
String word = str.substring(str.lastIndexOf("\\"));
\ character inside a string is escaping special characters (
",',\ and so forth). So using a
\ before them would make it literal, which means java treats what comes after it as if it's a regular character.
You can test to see what
would print. It would print
System.out.println("\" "); //would print one like this: " System.out.println("\' "); //would print one like this: '
and so on.