UTF-8 、 BIG5 互轉程式


Function 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 Function

Function 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

沒有留言: