开发者

C# Concatenate strings using backslash

开发者 https://www.devze.com 2023-04-10 05:07 出处:网络
I want to combine four variables like this : stringa,b,c,d; string Qno = \"a\\b\\c\\d\"; How to do for above result?开发者_JAVA百科string Qno = string.Format(\"{0}\\\\{1}\\\\{2}\\\\{3}\", a,b,c,d);

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?开发者_JAVA百科


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);


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);


Try this,

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

精彩评论

暂无评论...
验证码 换一张
取 消