How To Convert A List To A Delimited String



TODO:

Have you ever wanted to take a List<string> and convert it into a delimited string?

 

SOLUTION:

string someString = "test1.txt|test2.txt|test3.txt;
//split the string on | to get a List<string>
List<string> files = someString.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList<string>();

//now flatten it to a delimited string
string newValue = string.Join("|", files.Select(x => x).ToArray());

 

NOTES:

There are no notes on this topic



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading