kaarthikeyan
kaarthikeyan

Reputation: 11

C# Concatenate strings using backslash

I want to combine four variables like this :
string a,b,c,d;
string Qno = "a\b\c\d";

How to do for above result?

Upvotes: 1

Views: 4071

Answers (3)

KV Prajapati
KV Prajapati

Reputation: 94653

Try this,

string str = string.Format(@"{0}\{1}\{2}\{3}", a, b, c, d);

Upvotes: 3

Thomas Levesque
Thomas Levesque

Reputation: 292725

Are you trying to build a file path? If you do, check out the Path.Combine method:

string path = Path.Combine(a, b, c, d);

Upvotes: 4

Richard Dalton
Richard Dalton

Reputation: 35803

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

or if you have the strings in an array you can use string.Join:

string Qno = string.Join("\\", myArray);

Upvotes: 7

Related Questions