*
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 4375
    
    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 .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Using '\' operator in a string