漢字轉拼音首字母的java實現

2021-07-04 14:16:28 字數 1047 閱讀 6652

工作中經常會遇到的一些排序問題,比如 按漢字的拼音首字母排序,比如人名排序等,就要用到下面的方法了,思路:

1. 獲得漢字

2. 將漢字轉換成首字母,並記錄下(必要時儲存到資料庫)

3. 按首字母進行排序並展示

控制台輸出演示:

漢字轉首字母演示,請輸入漢字:           4654^*&^&*^_fdsf你i好3啊》?>?>*(*33p{}

}

package

pinyin;

/*** 漢字轉首字母縮寫

* *

@author

張云飛vir基於網上獲得的資料的修改2015-3-3

*/public

class

chinesetofirstcharutil

else

}return

tempstr;

}/*** 漢字轉拼音縮寫,清理無效字元(保留一些鍵盤字元)

* @param

str 漢字

* @return

string 縮寫

*/public

static

string convertandclear(string str)

/*** 漢字轉拼音縮寫,清理無效字元(清理任何非數字和字母)

* @param

str 漢字

* @return

string 縮寫

*/public

static

string convertandclearall(string str)

}return

sb.tostring();

}/*** 取單個字元的拼音聲母**

@param

c * //要轉換的單個漢字

* @return

string 拼音聲母

*/private

static

string getpychar(string c)

}

漢字轉拼音首字母

public string hz2py string hz 獲得漢字的區位碼 else if tmp 45253 tmp 45760 else if tmp 47761 tmp 46317 else if tmp 46318 tmp 46825 else if tmp 46826 tmp 47009...

漢字轉拼音或轉拼音首字母

漢字轉拼音或轉拼音首字母 public class chinesetospell private static string pyname new string 把漢字轉換成拼音 全拼 漢字字串 轉換後的拼音 全拼 字串 public static string characterconvertst...

漢字轉拼音或轉拼音首字母

漢字轉拼音或轉拼音首字母 public class chinesetospell private static string pyname new string 把漢字轉換成拼音 全拼 漢字字串 轉換後的拼音 全拼 字串 public static string characterconvertst...