ASP中漢字和Unicode的相互轉化

2021-06-22 13:21:23 字數 639 閱讀 8352

網上有很多類似的文章,但多數是一大堆**。其實asp有內建的處理unicode的函式,很簡單的幾句**就可以完成轉化:

推薦指數:★★★★☆

'將漢字轉化為unicode (不支援第二平面漢字,但幾乎極少有人能夠使用到這些漢字)

function getunicode(hanzi)

dim str

str = left(hanzi,1) '當然這裡需要判斷hanzi是乙個字元,如果需要多個字元請使用迴圈

if len(str)>0 then

getunicode = hex(ascw(str))

else

getunicode = ""

end if

end function

'將unicode轉化為漢字

funciton getchr(unicode) 『這裡的引數是上個函式得到的格式,如 4e00

if len(unicode)>0 then  

getchr = unescape("%u"&unicode)

else

getchr = ""

end if

end function

當然你還可以增加一些控制,比如對unicode範圍的檢查等等,以使得函式適應性更好。

unicode中漢字區間問題

今天接到乙個優化效能的任務,把乙個過濾非漢字字元的演算法效能提高一下,原來方法使用了如下方法 if character.unicodeblock.of c character.unicodeblock.cjk unified ideographs 這個方法內部使用了乙個二分查詢的演算法在乙個100多...

delphi 中 unicode 轉漢字 函式

近期用到這個函式,無奈沒有找到 delphi 自帶的,網上找了下 有類似的,沒有現成的,我需要的是 支援 u4f00 這種格式的,即前面帶標準的 u 於是改造了一下。下面是 解碼 函式 方便有需要的人吧,我自己也需要 unicode轉漢字 支援自動過濾非 unicode編碼,即非 unicode編碼...

unicode編碼 字元的轉換和得到漢字的區位碼

一 unicode編碼 字元的轉換截圖 二 unicode編碼 字元的轉換 using system using system.collections.generic using system.componentmodel using system.data using system.drawing...