Dilllllo Dilllllo - 1 month ago 7
Java Question

Illegal Escape Character "\"

i want to get the name at the final of a link so i did that

if( invName.substring(j,k).equals("\")){
copyf=invName.substring(0,j);}


so eclipse said String literal is not properly closed by a double-quote

how can i compaire String with this char \

Answer

The character '\' is a special character and needs to be escaped when used as part of a String, e.g., "\". Here is an example of a string comparison using the '\' character:

if (invName.substring(j,k).equals("\\")) {...}

You can also perform direct character comparisons using logic similar to the following:

if (invName.charAt(j) == '\\') {...}