【发布时间】:2017-01-08 13:18:54
【问题描述】:
我有一个读取逗号分隔文本文件的脚本,但是每当我在文件中提取的某个值上使用 Trim(str) 时,它都不起作用...
我的文本文件:
some string, anotherstring, onelaststring
some string, anotherstring, onelaststring
some string, anotherstring, onelaststring
some string, anotherstring, onelaststring
我的脚本:
Dim fso, myTxtFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set myTxtFile = fso.OpenTextFile("mytxt.txt")
Dim str, myTxtArr
txtContents myTxtFile.ReadAll
myTxtFile.close
myTxtArr = Split(txtContents, vbNewLine)
For each line in myTxtArr
tLine = Split(tLine, ",")
Trim(tLine(1))
If tLine(1) = "anotherstring" Then
MsgBox "match"
End If
Next
我的脚本从未达到“匹配”,我不知道为什么。
【问题讨论】:
-
您是否遇到了数组越界错误?
-
没有错误,只是没有修剪
-
trim("some string, anotherstring, onelaststring")永远不会等于"anotherstring"。也许您想在“,”上拆分行? -
很抱歉我没有包含我的代码的那部分,我更新了它。
-
啊啊啊。好的。很有道理。
标签: vbscript whitespace space trim blank-line