Array to String

  • Thread starter Thread starter Piero
  • Start date Start date
Piero said:
Hi, i have a string array, how can i convert it to a string?

Well, what do you want the result to be? Just one string with all the
strings concatenated together? Or separated with commas?
 
For example:

string[] foo = {"abc","def","ghi"};
string s1 = string.Concat(foo);
string s2 = string.Join(" ", foo);

Marc
 
For example:

string[] foo = {"abc","def","ghi"};
string s1 = string.Concat(foo);
string s2 = string.Join(" ", foo);

Marc

My result is a one string with the "\" separetor....
i use String.Join but the result is :
string s1= "abc\"def\"ghi\"; but it's wrong!
the right result must have s1 = "abc\def\ghi\";
 
string s1= "abc\"def\"ghi\"; but it's wrong!

Where are you looking at this? The IDE tool-tip displays it with
escape symbols. Try Console.WriteLine(s1) - it might actually be
right.

Marc
 
Where are you looking at this? The IDE tool-tip displays it with
escape symbols. Try Console.WriteLine(s1) - it might actually be
right.

Marc

i look this when i create a txt file. if i try with console.writeline
it's right!
but i must create an output file...
 
thank's to all! i resolve my problem!
my wrong istruvtion is String s1= string.join("\"",foo) and this
concatenates a backshals and quotes but i must concatenates only a
backslash and the right istruction is String s1 = string.join("\
\",foo).

thaks
bye
 
my wrong istruvtion is String s1= string.join("\"",foo) and this
concatenates a backshals and quotes

Actually that just concatenates quotes... but glad you are sorted ;-p

If you are doing a lot of this, the alternative syntax might be
clearer:

"\\" is the same as @"\";
 
Back
Top