vb实现将txt中所有"?"替换成换行符
答案:3 悬赏:30 手机版
解决时间 2021-03-02 06:00
- 提问者网友:星軌
- 2021-03-01 21:18
本目录下有一个约20kb的txt文本,用vb实现将这个文本文件中,所有"?"替换成换行符,然后仍然保存在txt文本文件中急需,谢谢!
最佳答案
- 五星知识达人网友:酒者煙囻
- 2021-03-01 22:54
Private Sub Command1_Click()
Dim temp$
Dim temp1$
Open App.Path & "\技术.txt" For Input As #1
Open App.Path & "\技术.tmp" For Output As #2
Do While Not EOF(1)
Line Input #1, temp
If temp Like "*?*" Then
temp1 = "" '清除它的值
For i = 1 To Len(temp) '处理问号并把新的值赋给temp1
If Mid(temp, i, 1) = "?" Then
temp1 = temp1 & Chr$(10)
Else
temp1 = temp1 & Mid(temp, i, 1)
End If
Next i
Print #2, temp1 '写入文件
End If
Loop
Close #1, #2Kill App.Path & "\技术.txt"
Name App.Path & "\技术.tmp" As App.Path & "\技术.txt"MsgBox "完成"
End Sub
Dim temp$
Dim temp1$
Open App.Path & "\技术.txt" For Input As #1
Open App.Path & "\技术.tmp" For Output As #2
Do While Not EOF(1)
Line Input #1, temp
If temp Like "*?*" Then
temp1 = "" '清除它的值
For i = 1 To Len(temp) '处理问号并把新的值赋给temp1
If Mid(temp, i, 1) = "?" Then
temp1 = temp1 & Chr$(10)
Else
temp1 = temp1 & Mid(temp, i, 1)
End If
Next i
Print #2, temp1 '写入文件
End If
Loop
Close #1, #2Kill App.Path & "\技术.txt"
Name App.Path & "\技术.tmp" As App.Path & "\技术.txt"MsgBox "完成"
End Sub
全部回答
- 1楼网友:不想翻身的咸鱼
- 2021-03-02 00:04
自己写了一个,当练手了。 将以下代码保存为vbs文件,然后直接运行: '//////////////////////////
'//
'// 文本批量替换示例
'// i=0
sch inputbox("输入要搜索的完整路径, 搜索和替换将包括子文件夹","文本搜索替换示例 by MacroChin @Mar 27, 2010")
MsgBox CStr(i)&"个文件成功替换。"Sub sch(s)
Set fs = CreateObject("Scripting.FileSystemObject")
Set fd = fs.GetFolder(s)
Set fi = fd.Files
Set sf = fd.SubFolders
For Each f in fi
rtn = f.Path
If fs.GetExtensionName(rtn)="txt" And f.size>0 Then
szTemp = fs.OpenTextFile(rtn, 1).ReadAll
szLast = Replace(szTemp, "?", vbCrLf)
If szLast<>szTemp Then
f.Delete
fs.CreateTextFile(rtn, 1).Write szLast
i=i+1
End If
End If
Next
If sf.Count<>0 Then
For Each l In sf
sch l
Next
End If
End Sub
- 2楼网友:轻熟杀无赦
- 2021-03-01 23:58
private sub command1_click()
p = "c:\vb.txt" '改成你的文件路径
dim inp, temp as string
open p for input as #1
do while not eof(1)
line input #1, inp
inp = replace(inp, "?", vbcrlf)
temp = temp & inp & vbcrlf
loop
close #1
open p for output as #1
print #1, temp
close #1
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯