我想在点击按钮后,将123.txt文本中的回车符全部删除,代码如下:Private Sub command1_click()Open "c:\123.txt" For Input As #1
Dim str1 As String
While Not EOF(1)
Line Input #1, str1
str1 = Replace(str1, vbCrLf, "")
Wend
Close #1End Sub但是按了后,怎么没反应呢
Dim str1 As String
While Not EOF(1)
Line Input #1, str1
str1 = Replace(str1, vbCrLf, "")
Wend
Close #1End Sub但是按了后,怎么没反应呢
Open "c:\tmp.txt" For Output As #2
Dim str1 As String
While Not EOF(1)
Line Input #1, str1
Print #2, str1;
Wend
Close #2
Close #1
Kill "c:\123.txt"
Name "c:\tmp.txt" As "c:\123.txt"
试试textstream 在fso里。
Private Sub Command1_Click()
Open "c:\123.txt" For Input As #1
Dim str1 As String
While Not EOF(1)
Line Input #1, str1
s = s & str1
Wend
Close #1
str1 = Replace(s, vbCrLf, "")
Open "c:\123.txt" For Output As #1
Print #1, s
Close #1End Sub
其实,这句不要也行。
直接把整个文件读了保存为字符串然后在Replace不就可以了 'Dim bytBuffer() As Byte
Dim strTmp As String
Dim Length As Long
Open "c:\boot.ini" For Binary As #1
Length = LOF(1)
'ReDim bytBuffer(Length - 1)
strTmp = String(Length, 0)
'Get #1, , bytBuffer
Get #1, , strTmp
Close #1
strTmp = Replace(strTmp, vbCrLf, "")
Debug.Print strTmp
'Debug.Print Replace(StrConv(bytBuffer, vbUnicode), vbCrLf, "")