File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Using '\' operator in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using Watch "Using New topic
Author

Using '\' operator in a string

kranthi devarapalem
Greenhorn

Joined: Sep 10, 2012
Posts: 14
Hi all

i want to add two strings with '\' parameter between them but it is not working. could someone please help me on this.

Example code:

"Kranthi"+"\"+"Kumar";

this is throwing complier time exception.

Thanks In Advance.

Regards
Kranthi.
kranthi devarapalem
Greenhorn

Joined: Sep 10, 2012
Posts: 14
got the answer we have to use "\\" insted of "\". Sorry For wating a post.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

\ is a special character in Java string literals (used for things like "\n"), so you have to escape it, by using \\.

Alternatively, in this case you could use a char literal rather than a String - so '\'.

Edit: ah, you got it yourself. Good .
 
jQuery in Action, 2nd edition
 
subject: Using '\' operator in a string