convert multiline comma separated textbox values with single quotes

后端 未结 1 800
慢半拍i
慢半拍i 2021-01-21 21:01

i have a code which converts the multiple selected items from listbox into a single line with comma separated values. now i want to achieve the same thing in multiline texbox, i

相关标签:
1条回答
  • 2021-01-21 21:42
    String.Join(",", txt.Lines.Select(s => "'" + s + "'"))
    

    String.Join is a method that gets a separator as first argument and a sequence of strings as the second. It solves the problem out of the box and more importantly solves the "last comma" problem which is so annoying when doing it with loops. You may use this method for the listbox code.

    The second argument maps an array of strings to the same strings with added single quotes. Basically it takes a bunch of strings and applies the transformation to each of them and returns a bunch of transformed strings. The transformation is represented in the lambda expression.

    0 讨论(0)
提交回复
热议问题