Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to resolve Invalid escape sequence in Java?

How can I use back slashes for a string in Java?

For example:

myString = "run -u A \\msomething\hsomething\something\something done";

Open in new window


It underlines the whole string in read it says:

Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

Open in new window


I solved the problem by doing the following but I am looking for a more elegant solution:

myString = "run -u A" + "\\\\" + "msomething" + "\\" + "hsomething" + "\\" + "something" + "\\" + "something done";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial