。net字符串解析

来源:百度知道 编辑:UC知道 时间:2024/05/12 04:17:01
string str = "今天12,13,14、15-16 明天23";
我要的结果 是 只过滤汉字 其他的全部原样留下 12,13,14、15-16 ,23
这样可以实现吗 ?

str = Regex.Replace(str, @"[\u4e00-\u9fa5]", "")

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace array
{
class Program
{
static void Main(string[] args)
{
string str = "今天12,13,14,15-16明天23";
string ans = chooseEnglish(str);
Console.WriteLine(ans);
}
static string chooseEnglish(string str)
{
string ans = "";
for (int i = 0; i < str.Length; ++i)
{
if (str[i]>256)
continue;
ans += str[i];
}
return ans;
}
}
}
注意逗号也有中英文之分