漢字按拼音排序

2021-06-27 07:39:24 字數 1866 閱讀 2996

漢字讀音資料庫:中的unihan_readings.txt

漢字讀音文件:

kmandarin是普通話讀音

通過查詢表將注音符號替換為英文本母,結尾帶乙個數字

#!/usr/bin/env python3

#-*- coding: utf-8 -*-

trans_table =

def trans(s):

for c in s:

if c in trans_table:

# 檢查韻母'üe'

if c == 'ü':

s2 = s.replace(c, trans_table[c][0])

for c2 in s2:

if c2 in trans_table:

return s2.replace(c2, trans_table[c2][0]) + trans_table[c2][1]

return s2 + '0'

else:

return s.replace(c, trans_table[c][0]) + trans_table[c][1]

return s + '0'

if __name__ == '__main__':

with open('unihan_readings.txt', 'r', encoding='utf-8', newline='\n') as database, open('unihan.table', 'w') as f:

print('unihan_data unihan_readings = , "{}"}},'.format(ch_value, value_transed), file=f)

print('};', file=f)

trans_table =

然後unihan.table裡就是漢字讀音表了。

我的專案裡是這麼查表的:

#include "windows.h"

#include #include namespace unihan_data;

#include "unihan.table"

const int tablesize = sizeof(unihan_readings) / sizeof(unihan_data);

/** * @brief 乙個漢字的讀音

* @param 漢字的unicode值

* @return 漢字的讀音,查詢不到為空

**/const char* unihan_chr(int value)

else

}if(value < unihan_readings[imid].value)

else if(value == unihan_readings[imid].value)

else

imid = (imin + imax) / 2;

}}} // anonymous namespace

int unihan_strcmp_w(wchar_t *s1, wchar_t *s2)

else if(!s2)

return 1;

size_t i = 0;

for(; s1[i] && s2[i]; ++i)

else

}// 比較到一者的結尾

if(s1[i])

return 1;

if(s2[i])

return -1;

return 0;

}int unihan_strcmp_a(char *s1, char *s2)

因為是windows的專案,所以用winsdk轉碼,不是windows專案就用libiconv吧。

MySQL漢字欄位按拼音排序

utf 8編碼的資料庫,如果希望漢字字段按照拼音排序 select from students order byconvert name using gbk 我們的mysql使用latin1的預設字符集,也就是說,對漢字字段直接使用gbk內碼的編碼進行儲存,當需要對一些有漢字的字段進行拼音排序時 特...

按漢字的拼音排序(c 實現)

原文 如何按漢字的拼音排序建築物名稱呢?這個問題是我在專案的實際開發中遇到的,下面是我解決的辦法 在網上搜尋了下 1 獲取建築物名稱的每個漢字的拼音首個字母,如下 using system using system.net using system.windows using system.wind...

C 按漢字拼音首字母排序

可參考以下部落格。c 使用微軟的visual studio international pack 類庫提取漢字拼音首字母 影子科技 c 漢字轉換拼音技術詳解 高效能 歷史的驅動 按漢字的拼音排序 c 實現 焦濤 漢字轉換為漢語拼音 全拼 首字母簡拼 任家 一 首先將漢字轉為拼音首字母縮寫 使用微軟提...