*
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
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: 4343
    
    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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using '\' operator in a string
 
Similar Threads
WA #1.....word association
what will be the sign!!
Good Online Java Tutorials
rich:tab
Right shift using array