Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

how to embed single backslash in string in c#

how do I print a single backslash

I want to print c: est

if I use

      string IN = "C:	est";

it's coming out as

      "C:	est"

and if I use

      string IN = @"C:	est";

it's coming out as

      "C:\test"

what's going on ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I assume by "coming out" you mean how it looks in the debugger or some other visualization. The debugger shows all control characters, so it uses \ to indicate one slash. Otherwise you wouldn't know if meant a slash followed by a t or a Tab character.

Either of these should give you the appropriate string:

string IN = @"C:	est";

or

string IN = "C:\test";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...