萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> .net編程 >> C#中判斷字符是否為中文?

C#中判斷字符是否為中文?

class="area">

protected bool   IsChineseLetter(string input,int index)
     ......{
        int code = 0;
        int chfrom = Convert.ToInt32("4e00", 16);    //范圍(0x4e00~0x9fff)轉換成int(chfrom~chend)
        int chend = Convert.ToInt32("9fff", 16);
        if (input != "")
         ......{
             code = Char.ConvertToUtf32(input, index);    //獲得字符串input中指定索引index處字符unicode編碼
           
           if (code >= chfrom && code <= chend)    
             ......{
                return true;     //當code在中文范圍內返回true

             }
            else
             ......{
                 return false ;    //當code不在中文范圍內返回false
             }
         }
          return false;
 }

copyright © 萬盛學電腦網 all rights reserved