开发者

VB script + change word in VB script on text file

开发者 https://www.devze.com 2023-01-03 20:59 出处:网络
how to change word in text file by VB script (like sed in开发者_如何学编程 unix)You can use the FileSystemObject Object. Some notes:

how to change word in text file by VB script (like sed in开发者_如何学编程 unix)


You can use the FileSystemObject Object. Some notes:

Set fs = CreateObject("Scripting.FileSystemObject")
sf = "C:\Docs\In.txt"

Set f = fs.OpenTextFile(sf, 1) ''1=for reading
s = f.ReadAll
s = Replace(s, "Bird", "Cat")
f.Close
Set f = fs.OpenTextFile(sf, 2) ''2=ForWriting
f.Write s
f.Close


Following steps: (when tackling a computing problem, divide and conquer!)

  1. Open the text file
  2. Save file contents to string variables
  3. Close the text file!
  4. Search variable for the word
  5. Replace the word(s)
  6. Save the variable as a text file overwriting old one

With the help of Google, you should be able to search and discover how to achieve all of the above points.

0

精彩评论

暂无评论...
验证码 换一张
取 消