目录
功能介绍
这个代码可以将VB变量的Unicode字符存为UTF-8格式的文本文件。
代码演示
'工程要引用 Microsoft ActiveX Data Objects 2.8,下面两个通用方法建议放在模块中
Public Sub SaveAsUTF8(ByVal Text As String,ByVal FileName As String)
Dim oStream As ADODB.Stream
Set oStream = New ADODB.Stream
oStream.Open
oStream.Charset = "UTF-8"
oStream.Type = adTypeText
oStream.WriteText Text
oStream.SaveToFile FileName,adSaveCreateOverWrite
oStream.Close
End Sub
Public Function LoadAsUTF8(ByVal FileName As String) As String
Dim oStream As ADODB.Stream
Set oStream = New ADODB.Stream
oStream.Open
oStream.Charset = "UTF-8"
oStream.LoadFromFile FileName
LoadAsUTF8 = oStream.ReadText()
oStream.Close
End Function