Dilllllo
Dilllllo

Reputation: 458

Illegal Escape Character "\"

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 \ ?

Upvotes: 26

Views: 204444

Answers (5)

Alberto Cerqueira
Alberto Cerqueira

Reputation: 1419

You can use:

\\

That's ok, for example:

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

Upvotes: 0

Kris Babic
Kris Babic

Reputation: 6304

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) == '\\') {...}

Upvotes: 34

if_zero_equals_one
if_zero_equals_one

Reputation: 1774

do two \'s

"\\"

it's because it's an escape character

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94439

I think ("\") may be causing the problem because \ is the escape character. change it to ("\\")

Upvotes: 0

Marcelo
Marcelo

Reputation: 11308

Use "\\" to escape the \ character.

Upvotes: 14

Related Questions