大家好:我有一个.ini文件频率要修改,可以要用VB了,(.ini文件应该和文本文件基本是一样的吧?),文件中"aabb"的字符大概有10个吧,我只需要把第二个"aabb"替代为"vbgood",怎搞?我刚才看了replace函数的详细说明,好象有点头绪,但是看不太明白。Replace(expression, find, replacewith[, start[, count[, compare]]]) 以下是全部替代的办法,寻求替代第二个"aabb"的方法.Open "c:\text1.ini" For Input As #1Open "c:\text2.ini" For Output As #2Dim i As StringDo While Not EOF(1)Line Input #1, ii = Replace(i, "aabb", "vbgood")Print #2, iLoopClose #1Close #2
2 回答
狐的传说
TA贡献1804条经验 获得超3个赞
dim s2 as string,str1 as string,i as string
Open "c:\text1.ini" For Input As #1
Do While Not EOF(1)
Line Input #1, i
str1 = str1 & i & vbcrlf
Loop
Close #1
s = Split(str1, "aabb")
t = Len(s(1)) + Len(s(0)) + 4
s2 = s2 & Left(str1, t) & "vbgood" & Right(str1, Len(str1) - t - 4)
Open "c:\text2.ini" For Output As #2
Print #2 , s2
close #2
千巷猫影
TA贡献1829条经验 获得超7个赞
Open "c:\text1.ini" For Input As #1
Open "c:\text2.ini" For Output As #2
Dim i As String
Do While Not EOF(1)
Line Input #1, i
If InStr(i, "aabb") <> 0 Then i = Mid(i, 1, InStr(i, "aabb") - 1) & "vbgood" & Mid(i, InStr(i, "aabb") + 4, Len(i))
Print #2, i
Loop
Close #1
Close #2
经过测试,成功通过!
- 2 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消