C#如何判断中文标点符号? C#如何判断中文标点符号?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 枚举出来,然后匹配。string symbol = ",。;?~!:‘“”’【】()"; 我不知道。但是我搜索了一下,从07年到现在的csdn帖子和其他google搜索结果中都没有比较好的方式。等等看谁有好办法吧。 //枚举出来就可以了Regex regex = new Regex(@"[,。;?~!:‘“”’【】()]");if (r.IsMatch(",。")) { Console.WriteLine(" is match "); } Regex regex = new Regex(@"[,。;?~!:‘“”’【】()]");if (r.IsMatch(",。")) { Console.WriteLine(" is match "); } using System.Text.RegularExpressions;//先导入这个使用正则表达式 Regex reg = new Regex(@"[\u4e00-\u9fa5]");//正则表达式 string str="smile 卡"; if (reg.IsMatch(str)) { Console.WriteLine("有汉字"); } else { Console.WriteLine("没汉字"); } 参考吧 用正则表达式判断Regex regex = new Regex(@"[,。;?~!:‘“”’【】()]") 自己搞定了,我用unicode编码方式返回byte数组,然后判断数组的值。 //方法很笨,很简单,不要见笑啊public bool getFlat(string noKnow){ byte[] bArry=System.Text.encoding.Unicode.getbytes(noKnow); if( bArry.Length=2) { if(bArry[1]!=0) return true; else return false; //当然noKnow有可能是汉字,因为汉字也是两个字节,但是汉字我已经用其他正则方法判断了,所以noKnow是不会有汉字传入的,有两个字节的就为 中文字符。方法笨,并且可能只适用我自己的应用。 }} //上面写错了,更正下方法public bool getFlat(string noKnow){ bool falt=false; byte[] bArry=System.Text.encoding.Unicode.getbytes(noKnow); if( bArry.Length=2) { if(bArry[1]!=0) falt=true; } return falt; } C# 关于BCD码的问题 求助:在窗体1点击按钮出现窗体2 用C#的comboBox显示数据的问题 大家来交我 关于保存参数大家怎么处理? PB能调用c#写的.dll吗? C#2005中如何用程序的方法修改settings中的数据库连接字符串?(初学者问题) 水晶报表怎么添加一个可输入的text框? 如何检测Frameworks有没有安装? 请问如何写出类似MP3播放器界面的程序,请各位高手给个思路 通过写服务来启动带有线程的程序、出现system.OutMomeryException C#打开txt文档显示乱码
string symbol = ",。;?~!:‘“”’【】()";
//枚举出来就可以了
Regex regex = new Regex(@"[,。;?~!:‘“”’【】()]");
if (r.IsMatch(",。"))
{
Console.WriteLine(" is match ");
}
if (r.IsMatch(",。"))
{
Console.WriteLine(" is match ");
}
string str="smile 卡";
if (reg.IsMatch(str))
{
Console.WriteLine("有汉字");
}
else
{
Console.WriteLine("没汉字");
}
参考吧
用正则表达式判断Regex regex = new Regex(@"[,。;?~!:‘“”’【】()]")
//方法很笨,很简单,不要见笑啊public bool getFlat(string noKnow)
{
byte[] bArry=System.Text.encoding.Unicode.getbytes(noKnow);
if( bArry.Length=2)
{
if(bArry[1]!=0) return true; else return false; //当然noKnow有可能是汉字,因为汉字也是两个字节,但是汉字我已经用其他正则方法判断了,所以noKnow是不会有汉字传入的,有两个字节的就为 中文字符。方法笨,并且可能只适用我自己的应用。
}}
{
bool falt=false;
byte[] bArry=System.Text.encoding.Unicode.getbytes(noKnow);
if( bArry.Length=2)
{
if(bArry[1]!=0) falt=true;
}
return falt;
}