This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to use \ in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to use \ in a string" Watch "how to use \ in a string" New topic
Author

how to use \ in a string

Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
i cannot use the \ backslash in a string. when i compile it gives a "illegal escape character" error. i tried to use '\' and then it just displayed quotes. any suggestions?


Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

See this thread...

http://www.coderanch.com/t/460417/Beginning-Java/java/help-please-PLEASE


GenRocket - Experts at Building Test Data
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Which is a great example of why descriptive subject are helpful, and non-descriptive ones are not.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deepika Singh
Greenhorn

Joined: Oct 10, 2008
Posts: 21
you have to use "\\" to print "\"

String s2 = "I have to write backslash \\";
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to use \ in a string
 
Similar Threads
amount currency datatype
Need help in java array
Looking for correct data type to take in stream of xml
Class definition
remove line feed and carriage return from a string