(轉)C#漢字首拼獲取方法
public static string getSpell(string cn)
{
string tempChar = "";
char[] temp = cn.ToCharArray();
for (int j = 0; j < temp.Length; j++)
{
byte[] arrCN = Encoding.GetEncoding("gb2312").GetBytes(temp[j].ToString());
if (arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
tempChar+= Encoding.Default.GetString(new byte[] { (byte)(65 + i) }).ToLower();
}
}
//tempChar += "?";
}
else
tempChar += temp[j];
}
return tempChar;
}[@more@]
{
string tempChar = "";
char[] temp = cn.ToCharArray();
for (int j = 0; j < temp.Length; j++)
{
byte[] arrCN = Encoding.GetEncoding("gb2312").GetBytes(temp[j].ToString());
if (arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
tempChar+= Encoding.Default.GetString(new byte[] { (byte)(65 + i) }).ToLower();
}
}
//tempChar += "?";
}
else
tempChar += temp[j];
}
return tempChar;
}[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/631872/viewspace-1032487/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- C# 獲取漢字首字母C#
- .Net(C#)獲取漢字聲母的方法C#
- C#漢字轉漢語拼音C#
- [轉]SQL獲取漢字拼音首字母函式SQL函式
- C#中漢字轉拼音C#
- C# WinForm獲取程式所在路徑方法C#ORM
- C#獲取程式當前路徑的方法C#
- C#獲取當前路徑的方法集合C#
- mssql sqlserver 獲取指定漢字的筆畫數的方法分享SQLServer
- C#獲取當前日期時間(轉)C#
- C#獲取根目錄的方法總結C#
- C# 獲取當前是星期幾的方法C#
- C#獲取檔案MD5值方法C#
- C# 獲取專案程式路徑的方法C#
- mysql獲取漢字的首字母MySql
- 獲取漢字串的拼音助記碼字串
- java獲取漢字的首字母Java
- C# 呼叫dll獲取dll物理路徑的方法C#
- C#中獲取當前路徑的幾種方法C#
- C# url資訊獲取C#
- 通過NameValuePairsValueProvider物件來獲取指定字首的KeyAIIDE物件
- 獲取_字首的oracle hidden parameter隱含引數Oracle
- 直播原始碼開發,vue漢字獲取字母首拼或拼音、大小寫原始碼Vue
- 摘抄Excel和FoxPro獲取漢字拼音首字母縮寫的方法.Excel
- mysql 中如何取得漢字欄位的各漢字首字母MySql
- 總結C#獲取當前路徑的7種方法C#
- C#中從Clipboard儲存獲取資料的方法C#
- iOS 獲取漢字【簡體中文】筆畫數iOS
- php獲取漢字的拼音 拼音首字母PHP
- Request.ServerVariables,C#獲取伺服器資訊,C#獲取訪問資訊ServerC#伺服器
- iOS漢字轉拼音的方法iOS
- js獲取元素的方法(獲取html元素的方法)JSHTML
- c# 獲取根目錄C#
- C#獲取HTML原始碼C#HTML原始碼
- 陣列呼叫c#讀取陣列中獲取最大最小值方法陣列C#
- 簡單方法在C#中取得漢字的拼音的首字母(轉)C#
- 在Excel中如何獲取漢字拼音首字母?Excel
- C# UTF8字串轉漢字C#字串