取漢字首字母

2021-04-28 02:00:45 字數 2975 閱讀 7435

public

function hz2py(byval hz as

string) as

string

dim sarr as

byte() = system.text.encoding.default.getbytes(hz)

dim len as

integer = sarr.length

if len > 1 then

dim array(2) as

byte

array = system.text.encoding.default.getbytes(hz)

dim i1 as

integer = cshort(array(0) - asc(controlchars.nullchar))

dim i2 as

integer = cshort(array(1) - asc(controlchars.nullchar))

dim tmp as

integer = i1 * 256 + i2

dim getpychar as

string = "*"

if tmp >= 45217 and tmp <= 45252 then

getpychar = "a"

endif

if tmp >= 45253 and tmp <= 45760 then

getpychar = "b"

endif

'if tmp >= 47761 and tmp <= 46317 then

if tmp >= 45765 and tmp <= 46294 then

getpychar = "c"

endif

if tmp >= 46318 and tmp <= 46825 then

getpychar = "d"

endif

if tmp >= 46826 and tmp <= 47009 then

getpychar = "e"

endif

if tmp >= 47010 and tmp <= 47296 then

getpychar = "f"

endif

if tmp >= 47297 and tmp <= 47613 then

getpychar = "g"

endif

if tmp >= 47614 and tmp <= 48118 then

getpychar = "h"

endif

if tmp >= 48119 and tmp <= 49061 then

getpychar = "j"

endif

if tmp >= 49062 and tmp <= 49323 then

getpychar = "k"

endif

if tmp >= 49324 and tmp <= 49895 then

getpychar = "l"

endif

if tmp >= 49896 and tmp <= 50370 then

getpychar = "m"

endif

if tmp >= 50371 and tmp <= 50613 then

getpychar = "n"

endif

if tmp >= 50614 and tmp <= 50621 then

getpychar = "o"

endif

if tmp >= 50622 and tmp <= 50905 then

getpychar = "p"

endif

if tmp >= 50906 and tmp <= 51386 then

getpychar = "q"

endif

if tmp >= 51387 and tmp <= 51445 then

getpychar = "r"

endif

if tmp >= 51446 and tmp <= 52217 then

getpychar = "s"

endif

if tmp >= 52218 and tmp <= 52697 then

getpychar = "t"

endif

if tmp >= 52698 and tmp <= 52979 then

getpychar = "w"

endif

if tmp >= 52980 and tmp <= 53640 then

getpychar = "x"

endif

if tmp >= 53689 and tmp <= 54480 then

getpychar = "y"

endif

if tmp >= 54481 and tmp <= 55289 then

getpychar = "z"

endif

return getpychar

else

return hz

endifend

function

'hz2py

public

function transpy(byval strhz as

string) as

string

dim strtemp as

string = ""

dim str as

string = ""

dim strlen as

integer = strhz.length

dim i as

integer

for i = 0 to strlen - 1

strtemp += hz2py(strhz.substring(i, 1))

next i

return strtemp

endfunction

'transpy

sql 取漢字首字母

create function fn getpy str nvarchar 4000 returns nvarchar 4000 用於加密 with encryption asbegin declare intlen intdeclare strret nvarchar 4000 declare t...

C 取漢字首字母

region 取中文首字母 public static string getfirstletter string paramchinese return strtemp 得到乙個漢字的拼音第乙個字母,如果是乙個英文本母則直接返回大寫字母 單個漢字 單個大寫字母 private static stri...

漢字首字母

在很多軟體中,輸入拼音的首寫字母就可以快速定位到某個詞條。比如,在鐵路售票軟體中,輸入 bj 就可以定位到 北京 怎樣在自己的軟體中實現這個功能呢?問題的關鍵在於 對每個漢字必須能計算出它的拼音首字母。gb2312漢字編碼方式中,一級漢字的3755個是按照拼音順序排列的。我們可以利用這個特徵,對常用...