请问怎样修改文本文件 我需要用vb打开某个文本文件,定位到某一行,某一个位置,添加一个字符,然后保存,请问这样的代码如何实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 文件整个读入字符串str1,用split(str1,vbCrLf)分割行,修改某一行(数组的某个元素),Join连接,print #写文件 Private Sub Command2_Click() Dim s() As String Dim Index As Long Dim LineID As Long Dim CharID As Long Dim sLine As String Dim sChar As String Open App.Path & "\1.txt" For Input As #1 Index = 0 Do While Not EOF(1) ReDim Preserve s(Index) Line Input #1, s(Index) Index = Index + 1 Loop Close #1 LineID = 1 '你要的行数 CharID = 3 '你要的字符号 sChar = "a" '你要插入的字符 sLine = s(LineID - 1) s(LineID - 1) = Left(sLine, CharID) & sChar & Right(sLine, Len(sLine) - CharID) Open App.Path & "\1.txt" For Output As #1 For Index = 0 To UBound(s) Print #1, s(Index) & vbCr Next Index Close #1 End Sub 如果是我我会将文本内部所有东西一并提出,第几行可以用SPLIT分解chr(13)就是你的行号,再从指定的行中搜索出符合你条件的字符位置,插入,将此行返回到总字符串中,重新写个文件 如何实现打开指定论坛TID的帖子 请问toolbar的一个问题(按钮状态判断,见正确答案立即给分) 各位,如何让webbrowser使用sock5连接网页 树控件添加子节点问题 从文件中读取指定的字节数,怎么做? 当winsock通信出错时 我是初学,问两个特初级的问题!cb6 谁有GVC 14400FAXMODEM(VF-1114V/C2)的驱动程序? 用vb调用vc写的dll时,出现了传递参数错位的问题 如何刷新Windows使注册表修改生效?给60分!! 本地记录集如何查询? 怎么连接带密码的access 2000数据库?
Dim s() As String
Dim Index As Long
Dim LineID As Long
Dim CharID As Long
Dim sLine As String
Dim sChar As String
Open App.Path & "\1.txt" For Input As #1
Index = 0
Do While Not EOF(1)
ReDim Preserve s(Index)
Line Input #1, s(Index)
Index = Index + 1
Loop
Close #1
LineID = 1 '你要的行数
CharID = 3 '你要的字符号
sChar = "a" '你要插入的字符
sLine = s(LineID - 1)
s(LineID - 1) = Left(sLine, CharID) & sChar & Right(sLine, Len(sLine) - CharID)
Open App.Path & "\1.txt" For Output As #1
For Index = 0 To UBound(s)
Print #1, s(Index) & vbCr
Next Index
Close #1
End Sub