ASP沒有原生的ASCII與Unicode轉碼函式,所以必須自訂函式,如下...
Function Chg_UNI(str) 'ASCII轉Unicode
dim old,new_w,iStr
old = str
new_w = ""
for iStr = 1 to len(str)
if ascw(mid(old,iStr,1)) < 0 then
new_w = new_w & "&#" & ascw(mid(old,iStr,1))+65536 & ";"
elseif ascw(mid(old,iStr,1))>0 and ascw(mid(old,iStr,1))<127 then
new_w = new_w & mid(old,iStr,1)
else
new_w = new_w & "&#" & ascw(mid(old,iStr,1)) & ";"
end if
next
Chg_UNI=new_w
End Function
Function Chg_ASC(str) 'Unicode轉ASCII
dim xStr,yStr,zStr,temp_word,flag
flag=0
xStr = instr(flag+1,str,"&#")
do until xStr = 0 or xStr < flag
xStr = instr(flag+1,str,"&#")
if xStr <> 0 then
yStr = mid(str,xStr,8)
select case instr(yStr,";")
case 8
zStr = chrw(mid(yStr,3,5))
case 7
zStr = chrw(mid(yStr,3,4))
case 6
zStr = chrw(mid(yStr,3,3))
case 5
zStr = chrw(mid(yStr,3,2))
end select
if instr(yStr,";") > 4 and asc(zStr) <> 63 then
str = replace(str,left(yStr,instr(yStr,";")),zStr)
end if
flag = xStr
end if
loop
Chg_ASC = str
End Function
Function Show_Data(str)
If isNull(str) Then
Show_Data = ""
Else
Show_Data = Chg_ASC(Chg_UNI(str))
End If
End Function
Function Save_ASC(str) 'Unicode轉ASCII 存入資料庫
dim x,y,z,temp_word,flag
flag=0
x = instr(flag+1,str,"&#")
do until x = 0 or x < flag
x = instr(flag+1,str,"&#")
if x <> 0 then
y = mid(str,x,8)
select case instr(y,";")
case 8
z = chrw(mid(y,3,5))
case 7
z = chrw(mid(y,3,4))
case 6
z = chrw(mid(y,3,3))
case 5
z = chrw(mid(y,3,2))
end select
if instr(y,";") > 4 then
str = replace(str,left(y,instr(y,";")),z)
end if
flag = x
end if
loop
Save_ASC = str
End Function
No comments:
Post a Comment