陋室铭
永远也不要停下学习的脚步(大道至简至易)

当切割字符串的是单个字符时可使用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 命名空间下。

posted on 2019-02-25 10:45  宏宇  阅读(1061)  评论(0编辑  收藏  举报