我们如何使用VB脚本逐字符地读取文本文件
答案 0 :(得分:2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\File.txt", 1)
Do Until objFile.AtEndOfStream
strCharacters = objFile.Read(1)
Wscript.Echo strCharacters
Loop
答案 1 :(得分:0)
设置文件路径并打开文本文件..
fileName = "D:\Project\ABC\vbfile.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(fileName)
现在逐行阅读,使用下面的代码
Do Until f.AtEndOfStream
WScript.Echo f.ReadLine
Loop
为了逐个字符地阅读它,请使用此代码
Do Until objFile.AtEndOfStream
strCharacters = f.Read(1)
Wscript.Echo strCharacters
Loop