Single backslash in a string. How??

R

Rafael Viana

Is it possible to have a string with a single backslash?

I want var to have the value "\foo"

And when I do something like:

var = "\foo"
I get
"foo"

But when I do:

var = "\\foo"
I get
"\\foo"

And when I do:

var = '\foo'
I get
"\\foo"

I even tried to remove one of the backslashes from the "\\foo" string,
but then I just get "foo" :-(


Thanks for reading, and I hope you can help me out
 
G

Ganesh Kumar

Rafael said:
Is it possible to have a string with a single backslash?

I want var to have the value "\foo"

And when I do something like:

var = "\foo"
I get
"foo"

But when I do:

var = "\\foo"
I get
"\\foo"

And when I do:

var = '\foo'
I get
"\\foo"

I even tried to remove one of the backslashes from the "\\foo" string,
but then I just get "foo" :-(


Thanks for reading, and I hope you can help me out




use double quotes don't use single quotes man
like var="\foo"

var="\\foo"
u will get
"\\foo"

var = "\foo"
u will get
"\foo"
 
R

Rob Biedenharn

Is it possible to have a string with a single backslash?

I want var to have the value "\foo"

And when I do something like:

var = "\foo"
I get
"foo"

But when I do:

var = "\\foo"
I get
"\\foo"

And when I do:

var = '\foo'
I get
"\\foo"

I even tried to remove one of the backslashes from the "\\foo" string,
but then I just get "foo" :-(


Thanks for reading, and I hope you can help me out

I just have to point out (since I don't think anyone else did) that
"\f" is a single character string: \f is an escape code for a form-
feed (ASCII 0x0C)

You're confusing the literal syntax for a backslash followed by a
letter with the actual contents of the string: "\\f".size == 2

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top