Convert: Vb/VBScript to read and save UTF-8 files

Source: Internet
Author: User

Turn: http://www.cnblogs.com/waver/articles/1283842.html

================================== VB Code ======== ======================================

 

 

Public Function SaveFile (filename as variant, strfilebody as variant) as Boolean

 

Dim ado_stream as object
Set ado_stream = Createobject ("ADODB. Stream ")

With ado_stream
. Type = 2
. Mode = 3
. Charset = "UTF-8"
. Open
. Writetext strfilebody
. Savetofile filename, 2
End

SaveFile = true
Set ado_stream = nothing
End Function

 

Public Function readutf8 (byval suf8file as string) as string
If Len (suttf8file) = 0 or Dir (suttf8file) = vbnullstring then exit function
Dim Ados as object
Set Ados = Createobject ("ADODB. Stream ")
With Ados
. Charset = "UTF-8"
. Type = 2
. Open
. Loadfromfile suf8file
Readutf8 =. readtext
. Close
End
Set Ados = nothing
End Function

 

 

================================ VBScript code ======== ======================================

Function LoadFile (PATH)
Dim stm2
Set stm2 = Createobject ("ADODB. Stream ")
Optional 2.type = 2
Listen 2.mode = 3
Ipv2.open

Ipv2.loadfromfile path
Listen 2.charset = "UTF-8"
'Stm2. charset = "Unicode"
'Stm2. charset = "gb2312"

Limit 2.position = 0
LoadFile = pai2.readtext
Commit 2.close
Set stm2 = nothing
End Function


Function writetofile (file, message)

Dim stm1
Set stm1 = Createobject ("ADODB. Stream ")
Required 1.type = 2
Secrets 1.open
Character 1.charset = "UTF-8"
'Stm1. charset = "Unicode"
Snapshot 1.position = snapshot 1.size

Upload 1.writetext LoadFile (File) + vbcrlf + message

Secrets 1.savetofile file, 2
Statement 1.close
Set stm1 = nothing
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.