.net利用正则表达式提取字符串中的数字
发布时间:2020-12-14 01:40:50 所属栏目:百科 来源:网络整理
导读:先留著,日後有用! string text = " 订单52|本次付款:4783|本单结清,";string pat = @"d+";Regex r = new Regex(pat);MatchCollection m = r.Matches(text);for (int i = 0; i m.Count; i++) { Response.Write("Match" + (i+1) +":"+ m[i].Value + "br /")
先留著,日後有用! string text = " 订单52|本次付款:4783|本单结清,"; string pat = @"d+"; Regex r = new Regex(pat); MatchCollection m = r.Matches(text); for (int i = 0; i < m.Count; i++) { Response.Write("Match" + (i+1) +":"+ m[i].Value + "<br />"); }
string text = " 订单5|本次付款:4783|本单结清,"; string pat = @"(d+)"; Regex r = new Regex(pat,RegexOptions.IgnoreCase); Match m = r.Match(text); int matchCount = 0; while (m.Success) { ++matchCount; Group g = m.Groups[1]; Response.Write("Match" + matchCount +":"+ g + "<br />"); m = m.NextMatch(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |