使用正则表达式
粗略的写就是这样
- string str = "我出门2398712了";
- //提取数字
- MatchCollection ms = Regex.Matches(str, @"\d+");
- //提取非数字
- MatchCollection ms2 = Regex.Matches(str, @"\D+");
- foreach (Match m in ms)
- {
- Console.WriteLine(m.Value);
- }
- foreach (Match m in ms2)
- {
- Console.WriteLine(m.Value);
- }
复制代码 |