首页 > 其他 > 详细

字符串切分 String.Split 和 Regex.Split

时间:2015-02-16 00:18:35      阅读:433      评论:0      收藏:0      [点我收藏+]

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

字符串切分 String.Split 和 Regex.Split

原文:http://www.cnblogs.com/mousewheel/p/4293585.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!