Create string from List<string>

  • Thread starter Thread starter Luigi Z
  • Start date Start date
L

Luigi Z

Hi all,
I have a List<string> from which I have to compose a caption (another
string) with a separator (-). If I use this code:

if (MyListString.Count != 0)
{
foreach(string s in MyListString
{
caption += orphan + "-";
}
}

it appers the - in the bottom of the string, like:

12345-54321-
How can I prevent this?

Thank you
 
hi Luigi,

Luigi said:
if (MyListString.Count != 0)
{
foreach(string s in MyListString
{
caption += orphan + "-";
}
}

it appers the - in the bottom of the string, like:

12345-54321-
How can I prevent this?
I would add s to caption...


mfG
--> stefan <--
 
Luigi Z laid this down on his screen :
Hi all,
I have a List<string> from which I have to compose a caption (another
string) with a separator (-). If I use this code:

if (MyListString.Count != 0)
{
foreach(string s in MyListString
{
caption += orphan + "-";
}
}

it appers the - in the bottom of the string, like:

12345-54321-
How can I prevent this?

Thank you

change the complete foreach to this:

caption = String.Join("-", MyListString.ToArray());


Hans Kesting
 
Back
Top