C 判斷中文字元的8種方法

2021-09-30 05:34:23 字數 2188 閱讀 1548

方法一

在unicode 字串中,中文的範圍是在4e00..9fff:cjk unified ideographs。

通過對字元的unicode編碼進行判斷來確定字元是否為中文。

protected

bool   ischineseletter

(string input,int index

)

...

else

...

return false;

方法二:

public bool ischina(string cstring)

else

}return boolvalue;

}方法三:

///

/// 判斷句子中是否含有中文

///

/// 字串

public bool wordsiscn(string words)

}return false;

}

方法四:

for (int i=0; i

/// 給定乙個字串,判斷其是否只包含有漢字

///

///

///

public bool isonlycontainschinese(string teststr)

else

}return true;

}///

/// 判斷乙個word是否為gb2312編碼的漢字

///

///

///

private bool isgbcode(string word)

else

else

}}///

/// 判斷乙個word是否為gbk編碼的漢字

///

///

///

private bool isgbkcode(string word)

else

else

}}///

/// 判斷乙個word是否為big5編碼的漢字

///

///

///

private bool isbig5code(string word)

else

else

}}上面是前輩們留下的,我想偷點懶。

方法七

引用從微軟亞洲語言開發包裡的simplified chinese pin-yin conversion library 裡提取chncharinfo.dll後

using microsoft.international.converters.pinyinconverter;

private bool ishanzi(char c)

方法八

引用從微軟亞洲語言開發包裡的simplified chinese pin-yin conversion library 裡提取chncharinfo.dll後

using microsoft.international.converters.pinyinconverter;

private bool ishanzi(char c)

catch

}附:有了這個開發,我這樣的菜鳥也可以很容易就玩轉漢字遊戲.

C 判斷中文字元

方法一 在unicode 字串中,中文的範圍是在4e00.9fff cjk unified ideographs。通過對字元的unicode編碼進行判斷來確定字元是否為中文。程式 protected bool ischineseletter string input,int index else r...

jquery 判斷中文字元的長度

方法一 使用正規表示式,如下 function getbytelen val else return len 方法二 使用字元unicode判斷 方法如下 function getbytelen val else return len function querytask var scantarge...

C 判斷中文字元(字串)

it168技術文件 在unicode 字串中,中文的範圍是在4e00.9fff cjk unified ideographs。通過對字元的unicode編碼進行判斷來確定字元是否為中文。protected bool ischineseletter string input,intindex else...