txt换行问题
txt内容
sfdawfwef,safwef
1fklwkj,klwefuo
1fwef,weffeeww
一共有600行数据
我想把它批量修改为
sfdawfwef,safwef|1fklwkj,klwefuo|1fwef,weffeeww
请问大大们改怎么写?
[解决办法]
Private Sub Command1_Click()
Open "c:\1.txt" For Input As #1 '假设c:\1.txt就是你的文件
Do While Not EOF(1)
S = InputB(LOF(1), #1)
Loop
Close #1
S = StrConv(S, vbUnicode)
S = Replace(S, vbCrLf, "|")
MsgBox S
End Sub
private sub command_click()dim s as stringon error goto errproc:filecopy "c:\1.txt", "c:\1.txt.bak"open "c:\1.txt" for binary as #1s = replace(input(lof(1), 1), vbcrlf, "|")close #1open "c:\1.txt" for output as #1print #1, sclose #1exit suberrproc:msgbox err.descriptionend sub
[解决办法]
其实很简单,就是把回车换行处理成|就行了。
回车换行在vb下可以用vbcrlf或vbnewline表示,也可以用chr(13)+chr(10)表示。
[解决办法]
Open "c:\1.txt" For Input As #1 '假设c:\1.txt就是你的文件
Do While Not EOF(1)
line input #1,s
t=t+s+"|"
Loop
Close #1
debug.print t
[解决办法]
演示源码如下:
Private Sub cmdOpen_Click() Dim strContent As String, strLine As String strContent = "" Open "C:\example.txt" For Input As #1 '打开文件 While Not EOF(1) If strContent <> "" Then strContent = strContent + "|" End If Line Input #1, strLine strContent = strContent + strLine Wend Close #1 MsgBox strContentEnd Sub