Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal Escape Character "\"

Tags:

I want to get the name at the end of a link so I did that

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

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

How can I compare String with this char \ ?

like image 852
Dilllllo Avatar asked Jun 06 '11 19:06

Dilllllo


People also ask

What is an illegal escape character?

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).

Why are illegal characters escaped?

Generally speaking, when the compiler gives you an error message, it tells you more than just "illegal escape character". It will show you the line and even the exact spot it thinks the error actually is: ? It GREATLY helps people help you if you post the ENTIRE message.

Why is it called an escape character?

It is a term related to that of an escape sequence and an Esc (escape) key. The character itself isn't "running away" from any other character.

What does it mean to escape a special character?

Escape Characters When you use braces to escape a single character, the escaped character becomes a separate token in the query. \ Use the backslash character to escape a single character or symbol. Only the character immediately following the backslash is escaped.


2 Answers

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) == '\\') {...}
like image 120
Kris Babic Avatar answered Sep 19 '22 13:09

Kris Babic


Use "\\" to escape the \ character.

like image 32
Marcelo Avatar answered Sep 21 '22 13:09

Marcelo