2009-05-26 [ASP] UTF-8跟BIG5互轉 24858 0 ASP 摘要:[ASP] UTF-8跟BIG5互轉 BIG5 --> UTF-8Function Convert_ASCII_Unicode(str) Dim old,new_w,j old = str new_w = "" For j = 1 To Len(str) if ascw(mid(old,j,1)) < 0 then new_w = new_w & "&#" & ascw(mid(old,j,1)) + 65536 & ";" ElseIf ascw(mid(old,j,1))>0 and ascw(mid(old,j,1))<127 then new_w = new_w & mid(old,j,1) Else new_w = new_w & "&#" & ascw(mid(old,j,1)) & ";" End if Next Convert_ASCII_Unicode = new_w End FunctionUTF-8 --> BIG5Function Convert_Unicode_ASCII(str) 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 And Asc(z) <> 63 then str = Replace(str,Left(y,InStr(y,";")),z) End if flag = x End if Loop Convert_Unicode_ASCII = str End Function 回首頁