Concating String Array with semicolons

后端 未结 2 1690
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 02:25

It is a pattern that occurs quite often in one part of our Framework. Given an Array of Strings, we have to concat all of them, seperated by Semicolons.

I´d like to know

相关标签:
2条回答
  • 2021-01-27 02:49

    You can use string.Join():

    String[] values = new String[] {"a","b","c","d"};
    var concat = string.Join(", ", values);
    

    This will result in something looking like this:

    a, b, c, d

    0 讨论(0)
  • 2021-01-27 02:49

    try:

    var result = string.Join(",", values.Where(s => !string.IsNullOrEmpty(s)));
    
    0 讨论(0)
提交回复
热议问题