如何判断一个字符串是否中文/日文/英文/韩文/或者其它。 if( System.Text.RegularExpressions.Regex.IsMatch(YourString,@"^[\u4E00-\u9FA5]+$")){ //yes} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个是针对中文么?还有英文呢另外。字符串不只有中文或者英文。比如字符串 “你好!Rob” 包含中文也包含英文。可以解决么? 中文/日文/韩文: [\u4E00-\u9FA5]英文:[a-zA-Z]if( System.Text.RegularExpressions.Regex.IsMatch(YourString,@"^[\u4E00-\u9FA5a-zA-Z]+$")){ //yes} 为什么最后lg没有任何输出?string Song_name = "大家好 - hello";string LG = null;if (System.Text.RegularExpressions.Regex.IsMatch(Song_name,@"^[\u4E00-\u9FA5a-zA-Z]+$")) { //中文/英文混合 LG = "3"; MessageBox.Show ("3"); }else{ if (System.Text.RegularExpressions.Regex.IsMatch(Song_name,@"^[a-zA-Z]+$")) { //英文 LG = "2"; MessageBox.Show ("2"); } if (System.Text.RegularExpressions.Regex.IsMatch(Song_name,@"^[\u4E00-\u9FA5]+$")) { //中文 LG = "1"; MessageBox.Show ("1"); }} "大家好 - hello", you have " " and "-" in it 判断前把这2种字符去掉。Song_name.Replace(" ","").Repalce("-","") 改了一下你程序中的判断顺序using System; class fen{ static void Main() {string Song_name = Console.ReadLine();string LG = null;if (System.Text.RegularExpressions.Regex.IsMatch(Song_name.Replace(" ","").Replace("-",""),@"^[\u4E00-\u9FA5]+$")) { //中文 LG = "中文"; Console.WriteLine(LG); }else if (System.Text.RegularExpressions.Regex.IsMatch(Song_name.Replace(" ","").Replace("-",""),@"^[a-zA-Z]+$")) { //英文 LG = "英文"; Console.WriteLine(LG); } else if (System.Text.RegularExpressions.Regex.IsMatch(Song_name.Replace(" ","").Replace("-",""),@"^[\u4E00-\u9FA5a-zA-Z]+$")) { //中文/英文混合中文 LG = "中英文混合"; Console.WriteLine(LG); }}} what do you want to match? 中文/日文/英文/韩文 alone? otherwise, why do you want to match in the first place? 理论上是不能百分之百判断准确的,因为他们的内码有重叠,如果正好是重叠区中的文字怎么办呢另外还要看你的中日韩是用的什么字符集,如果全是unicode可能要好办一些。你看IE他能百分之百判断准确文种吗?不行 如何将泛型集合对象绑定到dataGridView中??? C# 如何往socket写入Unicode编码不可见字符 如何用正则匹配得到ul里所有东西包括源代码 BACnet C# 如何捕获所有编辑框焦点事件 读取串口数据的问题(请高手指教,有点急) 诚聘PM及技术骨干(WPF) 工作地点北京 问个简单的问题,关于内存使用 SendKey.Send()问题 C#中转换问题 晕头转向 一个控件是如何写成的?
另外。字符串不只有中文或者英文。
比如字符串 “你好!Rob” 包含中文也包含英文。可以解决么?
英文:[a-zA-Z]if( System.Text.RegularExpressions.Regex.IsMatch(YourString,@"^[\u4E00-\u9FA5a-zA-Z]+$"))
{
//yes
}
string Song_name = "大家好 - hello";
string LG = null;
if (System.Text.RegularExpressions.Regex.IsMatch(Song_name,@"^[\u4E00-\u9FA5a-zA-Z]+$"))
{
//中文/英文混合
LG = "3";
MessageBox.Show ("3");
}
else
{
if (System.Text.RegularExpressions.Regex.IsMatch(Song_name,@"^[a-zA-Z]+$"))
{
//英文
LG = "2";
MessageBox.Show ("2");
}
if (System.Text.RegularExpressions.Regex.IsMatch(Song_name,@"^[\u4E00-\u9FA5]+$"))
{
//中文
LG = "1";
MessageBox.Show ("1");
}
}
Song_name.Replace(" ","").Repalce("-","")
class fen
{
static void Main()
{
string Song_name = Console.ReadLine();
string LG = null;
if (System.Text.RegularExpressions.Regex.IsMatch(Song_name.Replace(" ","").Replace("-",""),@"^[\u4E00-\u9FA5]+$"))
{
//中文
LG = "中文";
Console.WriteLine(LG);
}
else if (System.Text.RegularExpressions.Regex.IsMatch(Song_name.Replace(" ","").Replace("-",""),@"^[a-zA-Z]+$"))
{
//英文
LG = "英文";
Console.WriteLine(LG);
}
else if (System.Text.RegularExpressions.Regex.IsMatch(Song_name.Replace(" ","").Replace("-",""),@"^[\u4E00-\u9FA5a-zA-Z]+$"))
{
//中文/英文混合中文
LG = "中英文混合";
Console.WriteLine(LG);
}
}
}
另外还要看你的中日韩是用的什么字符集,如果全是unicode可能要好办一些。
你看IE他能百分之百判断准确文种吗?不行