You need to use
String word = str.substring(str.lastIndexOf("\\"));
the \
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
System.out.println("\\");
would print. It would print \
.
So:
System.out.println("\" "); //would print one like this: "
System.out.println("\' "); //would print one like this: '
and so on.