当切割字符串的是单个字符时可使用String.Split

string strSample="ProductID:20150215,Categroy:Food,Price:15.00";
string[] sArray=strSample.Split(',');    //注意,这里用的是单引号,而非双引号

 

当切割字符串的是多个字符时只能使用Regex.Split
string strSample="ProductID:20150215$_$Categroy:Food$_$Price:15.00";
string[] sArray=Regex.Split(strSample,@"\$_\$",RegexOptions.IgnoreCase);  //注意,需做特殊字符的转义。另外Regex 在System.Text.RegularExpressions 命名空间下。

相关文章:

  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2021-10-18
猜你喜欢
  • 2021-07-18
  • 2021-11-22
  • 2021-11-22
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
相关资源
相似解决方案