java正则表达式C#
最护眼的颜色
#CFE8CC
207232204
//Java版本 //替换字符串s中的所有字母(这里替换为“”) public static String getNumberInfo(StringBuffer s) { String ptn = "[a-zA-Z]+"; Pattern p = Pattern.compile(ptn, Pattern.DOTALL); Matcher m = p.matcher(s); while (m.find()) { s = s.replace(m.start(0), m.end(0), ""); m = p.matcher(s); } return s; } //C# 版本 public Form1() { InitializeComponent(); StringBuilder s = new StringBuilder(@"haohao,9.36,ssf ,123, good ,421f,ffd,fz,5.26,,,asfggds,13123"); Test2(s); } private void Test2(StringBuilder s) { String ptn = "[a-zA-Z]+"; MatchCollection matchCol = Regex.Matches(s.ToString(), ptn, RegexOptions.Multiline); for (int i = matchCol.Count - 1; i >= 0; i--) { Match item = matchCol[i]; s.Remove(item.Index, item.Length); } txtScan.AppendText(string.Format("结果:{0}\r\n", s.ToString())); }
相关推荐
wangzhaotongalex 2020-10-20
wyq 2020-11-11
TLROJE 2020-10-26
风雨断肠人 2020-10-13
duanqingfeng 2020-09-29
rechanel 2020-11-16
cshanzhizi 2020-10-16
luofuIT成长记录 2020-09-22
phphub 2020-09-10
taomengxing 2020-09-07
MaggieRose 2020-08-19
flyingssky 2020-08-18
山水沐光 2020-08-18
jyj00 2020-08-15
AHuqihua 2020-08-09
山水沐光 2020-08-03