In C#: Add Quotes around string in a comma delimited list of strings

后端 未结 16 1813
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 08:18

This probably has a simple answer, but I must not have had enough coffee to figure it out on my own:

If I had a comma delimited string such as:

string li         


        
16条回答
  •  春和景丽
    2021-01-30 08:53

    I have found a new solution for this problem

    I bind a list by selected items values from the grid using linq, after that added a comma delimited string for each string collections by using String.Join() properties.

    String str1 = String.Empty;
    String str2 = String.Empty;              
    //str1 = String.Join(",", values); if you use this method,result "X,Y,Z"
         str1 =String.Join("'" + "," + "'", values);
    //The result of str1 is "X','Y','Z"
         str2 = str1.Insert(0, "'").Insert(str1.Length+1, "'");
    //The result of str2 is 'X','Y','Z'
    

    I hope this will helpful !!!!!!

提交回复
热议问题