我有一個文本文件,我需要與兩個分隔符逐行分割。分割與多個分隔符
'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將臨時輸出文件重命名爲原始文件的名稱。這也有利於減少內存。 –
謝謝你的回答。你將如何逐行閱讀並正確地分割文本? –