Link to home
Start Free TrialLog in
Avatar of GroganJ
GroganJ

asked on

Inserting a control character into a string

Hi,

I have 2 strings and I want to put the character "\" between them.

So, I have
string a = "MMM";
string b = "I01";
string c = a+"\"+b;

so c looks like "MMM\I01".

However, no matter how I structure the addition, the single \ is always replaced with a \\.

Any thoughts how to achieve this?

John.
Avatar of TvMpt
TvMpt
Flag of Portugal image

string c= string.Format("{0}\\{1}", a,b);

Open in new window

Avatar of GroganJ
GroganJ

ASKER

That still gives me a double \

User generated image
A single quote triggers an error.
string c= string.Format(@"{0}\{1}", a, b);

this must work
ASKER CERTIFIED SOLUTION
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GroganJ

ASKER

Thanks Guys - the problem was that VS was showing double. When it passed the string to the end application, it worked just fine.