Can anyone help me find the LastIndexOf ‘\’ in a string in java? I wrote the code as:
int i = app.lastIndexOf('\');
app is my string, but there is a error as “Invalid character constant”. I tried using double quotes but still no use. Can anyone help me on this?
The
\character is used to escape other characters, in order to print special characters.For example,
'\n'is the “newline” character,'\t'is the “tab” character,'\''is the literal', etc.In order to use a
\in a string, you have to escape it:\\.Use
app.lastIndexOf('\\');