201804102140->字符串操作檢測是否含有中文
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 檢測中文字符
{
class Program
{
static void Main(string[] args)
{
//利用ascll碼查出中文
//漢字的 UNICODE 編碼範圍是0x4e00-0x9fbb,即0x4e00<=char<=0x9fbb
HasChinese();
Console.ReadKey();
}
private static void HasChinese()
{
string read = string.Empty;
bool CheckChinese = false;
int num = 0;
read = Console.ReadLine();
for (int i = 0; i < read.Length; i++)
{
if ((int)read[i]>127)//ascll裏邊漢字大於127,英文0-127
{
CheckChinese = true;
++num;
}
}
if (CheckChinese)
{
Console.WriteLine("此字符串中含有中文,有{0}箇中文",num);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 檢測中文字符
{
class Program
{
static void Main(string[] args)
{
//利用ascll碼查出中文
//漢字的 UNICODE 編碼範圍是0x4e00-0x9fbb,即0x4e00<=char<=0x9fbb
HasChinese();
Console.ReadKey();
}
private static void HasChinese()
{
string read = string.Empty;
bool CheckChinese = false;
int num = 0;
read = Console.ReadLine();
for (int i = 0; i < read.Length; i++)
{
if ((int)read[i]>127)//ascll裏邊漢字大於127,英文0-127
{
CheckChinese = true;
++num;
}
}
if (CheckChinese)
{
Console.WriteLine("此字符串中含有中文,有{0}箇中文",num);
}
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.