开发者

How to read a file character by character in VB script

How can we read the text file character by character using VB scri开发者_如何学Gopt


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


To set the file path and open the text file..

fileName = "D:\Project\ABC\vbfile.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(fileName)

Now to read it line by line, use below code

Do Until f.AtEndOfStream
  WScript.Echo f.ReadLine
Loop

In order to read it character by character use this code

Do Until objFile.AtEndOfStream
    strCharacters = f.Read(1)
    Wscript.Echo strCharacters
Loop


0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜