在ASP將字串轉成 Big5 位元串以十六進制表示

古老的 ASP 程式通常都在 ANSI 模式下。

近年來已朝向 Unicode (UTF-8) 的環境開發
在第一行加入: <%@LANGUAGE="VBScript" CODEPAGE="65001" %>
可以讓程式碼、語言核心、HTTP IO 都使用 Unicode 了。

如果有一個特殊狀況要把 Unicode 網頁的文字轉回去 Big5 怎麼辦呢?


'=== 將(Unicode)字串轉成 Big5 位元串以十六進制表示
Private Function HexBig5(strData)
Dim o,B,I,out
Set o = Server.CreateObject("ADODB.Stream")

o.Charset = "big5"
o.Mode = 3 '1讀 2寫 3讀寫
o.Type = 2 '1二進制 2純文字
o.Open
o.WriteText strData

'o.SaveToFile Server.MapPath("t.txt"),2 '測試輸出文字檔
o.Position = 0 '從頭開始
o.Charset = "big5"
o.Type = 1
B = o.Read

out = ""
For I= 1 To o.size
out = out & HexB(AscB(MidB(B,I,1)))
Next
HexBig5 = out
End Function

Private Function HexB(value)
hexB = Right("0" & HEX(value),2)
End Function

5 個回應:

Fangyaya 提到...

fitflops sale clearance
michael kors outlet
asics shoes
christian louboutin outlet
ralph lauren clearance outlet
ralph lauren outlet
michael kors outlet
kobe 11
juicy couture
mont blanc
polo ralph lauren outlet
coach outlet online
michael kors outlet
michael kors outlet online
cheap oakley sunglasses
michael kors purses
coach factory outlet
rolex submariner
coach outlet
christian louboutin outlet
michael kors outlet clearance
kate spade
louis vuitton outlet stores
louis vuitton outlet
ray ban sunglasses
tods outlet
jordans
louis vuitton outlet
hollister clothing store
true religion jeans
20167.26chenjinyan

chenmeinv0 提到...

north face jackets
moncler coats
fitflop shoes
ugg outlet
ray ban outlet
canada goose sale
nike tn pas cher
michael kors outlet
oakley sunglasses outlet
pandora jewelry
2016.10.27xukaimin

chenlina 提到...

replica watches
rolex watches
ugg outlet
michael kors handbags
retro jordans 11
christian louboutin shoes
oakley sunglasses wholesale
jordans
ugg outlet
true religion jeans
chenlina20170109

Meiqing Xu 提到...

coach outlet
tiffany outlet
canada goose outlet
michael kors outlet
ed hardy
birkenstocks
air jordan retro
yeezy boost
longchamp uk
cheap oakley sunglasses
20170224caiyan

chenlina 提到...

north face
toms outlet
michael kors bags
louis vuitton handbags
ray ban sunglasses
michael kors handbags
hermes outlet
nike outlet store
michael kors
coach outlet
chenlina20170720

張貼留言