如何在Array List中使用多个分隔符

时间:2016-04-28 08:26:54

标签: c# asp.net split delimiter

我想问你下面的代码:

 string[] seledCats = new string[0];

 string condsCats = EzCoding.Web.UI.QueryStringParsing.GetValue(
   "CondsCats",
   EzCoding.Web.RequestMethod.Post);

 if (condsCats != null)
 {
     seledCats = condsCats.Split(new string[] { "," },
                                 StringSplitOptions.RemoveEmptyEntries);
 }

在数组列表中插入所选数据后,输出A1,A2, 但我希望将其显示为'A1','A2'

那么,我该怎么做呢? 感谢。

2 个答案:

答案 0 :(得分:4)

您可以使用这个小LINQ查询:

string condsCats = EzCoding.Web.UI.QueryStringParsing.GetValue("CondsCats",EzCoding.Web.RequestMethod.Post);
string[] seledCats = null;
if(condsCats != null)
    seledCats = condsCats 
        .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
        .Select(s => String.Format("'{0}'", s))
        .ToArray();

答案 1 :(得分:0)

<form action="" method="post">
  <div class="grid">
    <textarea rows="20" cols="15" name="" class="grid-cell"></textarea>
    <div class="grid-cell">
      <input type="submit" value="10 >>> 13" name="submit_a" class=""/>
      <input type="submit" value="10 <<< 13" name="submit_b" class=""/>
    </div>
    <textarea rows="20" cols="15" name="" class="grid-cell"></textarea>
  </div>
</form>