js實現漢字轉拼音(解決首字母排序問題)

2021-09-23 05:56:08 字數 913 閱讀 1484

漢字有21個聲母:b, p, m, f, d, t, n, l, g, k, h, j, q, x, zh, ch, sh, r, z, c, s

有韻母24個,其中單韻母有6個:a, o, e, i, u, v, 復韻母有18個:ai , ei, ui , ao, ou, iu , ie, ve, er, an , en , in, un , vn , ang, eng, ing , ong

假設聲母和韻母兩兩組合的話,會有24x21=504種組合,實際情況是有些組合是沒有意義的,比如zv, zie, zve等,去除這部分後,還剩餘401種;這就為物件列舉的實現提供了可能,結合unicode編碼表,實現起來就很簡單了。直接上**:

var pinyin =

;// 漢字轉拼音

function

convertpinyin

(str)

else

if(name !==

false)}

i1=i1.

replace

(/ /g

,'-');

while(i1

.indexof

('--'

)>0)

returni1;

}// 在物件中搜尋

function

arraysearch

(l1, l2)

}return

false;}

// 首字母大寫

function

ucfirst

(l1)

}<

/script>

注意:多音字和生僻字在轉換會有問題。

js實現漢字轉拼音

漢字轉拼音首字母

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...