要隔離壞的行尾,首先要將好的行尾轉換爲摘要。然後,您可以刪除vbCrLF或vbLf,這會將它們背離它們。最後一步是通過反轉摘要來恢復良好的行結束。
dim str as string
'use your favorite method to read the TXT file into the str variable
str = Replace(str, chr(59) & vbCrLf & "TEQ;", chrw(8203)) 'convert good eol to unicode zero-length space
str = Replace(str, vbLf, vbNullString) 'remove bad eols
str = Replace(str, chrw(8203), chr(59) & vbCrLf & "TEQ;") 'revert back to good eol
'write the str back to the TXT file
它不會是一個壞主意,扔幾個.TXT文件放到一個十六進制編輯器,以確定是否壞結束線,vbCrLf(CHR(13)&人權委員會創建( 10))或者只是vbLf(Chr(10))。儘管我懷疑好的結果是vbCrLF,而壞的結果只是vbLf,但是和好的結尾一樣。
下面的子過程需要您進入VBE的工具►引用,並添加Microsoft腳本運行時到項目中。
Sub fix_TEQ_text()
Dim str As String, fp As String, fn As String
Dim fso As New FileSystemObject, ts As TextStream
fp = Environ("TEMP")
fn = Dir(fp & Chr(92) & "TEQ*.txt", vbNormal)
Do While CBool(Len(fn))
If Not CBool(InStr(1, fn, "_fixed", vbTextCompare)) Then
Set ts = fso.OpenTextFile(fp & Chr(92) & fn, ForReading)
str = ts.ReadAll
ts.Close
str = Replace(str, Chr(59) & vbCrLf & "TEQ;", ChrW(8203)) 'convert good eol to unicode zero-length space
str = Replace(str, vbLf, vbNullString) 'remove bad eols
str = Replace(str, ChrW(8203), Chr(59) & vbCrLf & "TEQ;") 'revert back to good eol
Set ts = fso.CreateTextFile(fp & Chr(92) & Replace(fn, ".txt", "_fixed.txt"), True)
ts.Write str
ts.Close
End If
fn = Dir
Loop
End Sub
您將要改變的文件路徑(例如FP)和文件掩碼(目前"TEQ*.txt"
這符合我的樣本TXT文件)。
您可以在「查找」字段中放置空格。 (: –
感謝您的回答!但找到線不是我的問題,我已經整理出來了,但因爲有41K +,我不想手動做退格41000次,所以我需要一些東西。全部更換 –
我從Excel出口因此,每列分隔用semikolon 例如,它看起來是這樣的: TEQ; 2341; GJGJG; 092139; 9078; dbhd; TEQ; 1241; GJGJG ; 093319; 9018; dbhd。 ;; 3號線將是一個腐敗的一個 –