我需要在文本中删除额外的逗号和回车符。
此代码仅删除额外的逗号:
Sub test()
Dim fn As String, txt As String
fn = Application.GetOpenFilename("TextFiles,*.txt")
If fn = "" Then Exit Sub
txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
With CreateObject("VBScript.RegExp")
.Global = True: .MultiLine = True
.Pattern = ",+$"
Open Replace(fn, ".txt", "_Clean.txt") For Output As #1
Print #1, .Replace(txt, "")
Close #1
End With
End Sub
如何删除文本处的额外断行/回车?
答案 0 :(得分:1)
如果您只想删除文件的结束处的CR / LF,只需在;
语句的末尾添加Print
,即
Print #1, .Replace(txt, "");