admin管理员组

文章数量:1794759

VB

VB

方法举例

Dim arr
arr = array("a|11","b|22","c|3","d|f")
file = "a.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(file, 1)
txt = f.ReadAll
f.Close
For Each a In arrt = split(a, "|")txt = replace(txt, t(0), t(1))
Next
Set f = fso.OpenTextFile(file, 2)
f.Write txt
msgbox "Done"

修改前

修改后

代码出处:.html

更新读取UTF-8的方法

Function ReadFile(FileUrl)Dim strSet stm = CreateObject("ADODB.stream")stm.Type = 2stm.mode = 3stm.charset = "UTF-8"stm.Openstm.loadfromfile FileUrlstr = stm.readtextstm.CloseSet stm = NothingReadFile = str
End FunctionDim arr
arr = array("a|11","b|22","c|3","d|f")Dim str
file = "a.txt"
str = ReadFile(file)
For Each a In arrt = split(a, "|")str = replace(str, t(0), t(1))
NextSet fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(file, 2)
f.Write str
msgbox "Done"

本文标签: vb