尝试将分隔符插入到文本文档中

时间:2013-11-14 16:24:28

标签: vbscript

我正在尝试在文本文件的每一行的某些点放置一个垂直条。我的代码非常简单我很确定......但是当我尝试运行它时没有任何反应。我甚至没有收到错误。它应该写入的文件只是一个空白文本文件

Const ForReading = 1
Const ForWriting = 2

arrCommas =  Array(10,14,21,24,39,43,46,61,72,79,82,85,88,91,94,97,101,142,173,189,192,198,205,211,218,222,229,236,240)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsedited\mbsfact102013_linebreaks.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
intLength = Len(strLine)
For Each strComma in arrCommas
    strLine = Left(strLine, strComma - 1) + "|" + Mid(strLine, strComma, intLength)
Next
strText = strText & strLine & vbCrLf
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsfinal\mbsfact102013_delimited.txt", ForWriting)
objFile.Write strText
objFile.Close

1 个答案:

答案 0 :(得分:-1)

Const ForReading = 1
Const ForWriting = 2

arrCommas =  Array(10,14,21,24,39,43,46,61,72,79,82,85,88,91,94,97,101,142,173,189,192,198,205,211,218,222,229,236,240)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsedited\mbsfact102013_linebreaks.txt", ForReading)

strTextFile = objFile.ReadAll
objFile.Close

aTextFile = Split(strTextFile, vbCRLF)

strText = ""
For Each strLine In aTextFile
    intLength = Len(strLine)
    For Each strComma in arrCommas
        strLine = Left(strLine, strComma - 1) + "|" + Mid(strLine, strComma, intLength)
    Next
    strText = strText & strLine & vbCrLf
Next

Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsfinal\mbsfact102013_delimited.txt", ForWriting)
objFile.Write strText
objFile.Close