2013年8月8日 星期四

[VisualBasic] Unicode碼 轉Unicode中文字

fso.CreateTextFile("c:\test.txt", True, True) 'unicode文字檔
 fso.OpenTextFile("c:\test.txt", ForAppending, True, TristateTrue)

str:待轉換的中文+Unicode編碼


Function Convert(str)

str = Trim(str)

Dim name As String

If InStr(1, str, "&#", 0) > 0 Then '表示有待轉換的編碼

Dim tempArr, tempArr2

tempArr = Split(str, "&#")

For i = 0 To UBound(tempArr)

If IsNumeric(tempArr(i)) Then
name = name & ChrW(tempArr(i))
Else
tempArr2 = Split(tempArr(i), ";")

For j = 0 To UBound(tempArr2)

If IsNumeric(tempArr2(j)) Then
name = name & ChrW(tempArr2(j))
Else

name = name & tempArr2(j)

End If

Next

End If

Next

Convert = name
Else
Convert = str

End If

End Function

沒有留言:

張貼留言