VB6存取UTF-8文件

前端之家收集整理的这篇文章主要介绍了VB6存取UTF-8文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目录

功能介绍

这个代码可以将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
原文链接:https://www.f2er.com/vb/256905.html

猜你在找的VB相关文章