删除txt文件中的最后一个单词

早上好

我有一个名为“TXT”与4行的TXT文件。 而我的问题是我想删除最后3行中的最后2个单词。

这是我的txt文本:

"vol" "vui one high" one high "vui one front " two high "vuil high front " three high 

而要删除的文字是引号后面的2。


我有一个代码,但在这一刻,它只允许replace一个字这里是我的代码的开始:

 Sub CommandButton1_Click() Dim sBuf As String Dim sTemp As String Dim iFileNum As Integer Dim sFileName As String ' Edit as needed sFileName = "C:\Users\bquinty\Desktop\txt.txt" iFileNum = FreeFile Open sFileName For Input As iFileNum Do Until EOF(iFileNum) Line Input #iFileNum, sBuf sTemp = sTemp & sBuf & vbCrLf Loop Close iFileNum sTemp = Replace(sTemp, "word to remplace", "word wanted") 'Save txt file as (if possible) iFileNum = FreeFile sFileName = "C:\Users\bquinty\Desktop\txt.txt" Open sFileName For Output As iFileNum Print #iFileNum, sTemp Close iFileNum End Sub 

感谢您可以给我的所有帮助/build议。

在VBA中逐行使用“ 读取/parsing”文本文件的答案

作为开始:

 Sub test() Dim FileNum As Integer Dim DataLine As String Dim newDataLine() As String FileNum = FreeFile() Open "c:\Delete_NOW.txt" For Input As #FileNum While Not EOF(FileNum) Line Input #FileNum, DataLine newDataLine = Split(DataLine, " ") If UBound(newDataLine, 1) > 3 Then ReDim Preserve newDataLine(UBound(newDataLine, 1) - 3) Wend End Sub