我有一个文本文件,我需要与两个分隔符逐行分割。分割与多个分隔符
'Testing' # Libname 'Testing2' #Libname2
但是,我要的是:
Testing Libname Testing2 Libname2
就目前我的代码只是把以下内容:
Testing Libname Testing2 Libname2
任何想法?
Set objFile = objFSO.OpenTextFile(WScript.Arguments(0) & "\listofpaths.csv", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, Chr(34), "'") 'Replace Double Quote for Single Quote
strNewText = Replace(strNewText, "'", "#") 'Replace
CharacterCount = (Len(strNewText) - Len(Replace(strNewText, "#", "")))
Set objNewFile = objFSO.CreateTextFile(WScript.Arguments(0) & "\listofpaths.csv", ForWriting, True)
objNewFile.Write strNewText
objNewFile.Close
Set objFile = objFSO.OpenTextFile(WScript.Arguments(0) & "\listofpaths.csv", ForWriting, True)
For i=1 To CharacterCount
splitstr = Split(strNewText, "#")
objFile.WriteLine splitstr(i) '& "#" & splitstr1(i)
i = i + 1
Next
objFile.Close
WScript.Echo " Process completed "
要保留线的概念,由线而不是使用.ReadAll过程中输入文件行。使用两个文件同时读写。如果要使用相同的文件名,可以在最后使用fso.MoveFile将临时输出文件重命名为原始文件的名称。这也有利于减少内存。 –
谢谢你的回答。你将如何逐行阅读并正确地分割文本? –