我其实也不是非要replace函数不可,只要可以达到目的就可以了。

大家好:
我有一个.ini文件频率要修改,可以要用VB了,(.ini文件应该和文本文件基本是一样的吧?),文件中"aabb"的字符大概有10个吧,我只需要把第二个"aabb"替代为"vbgood",怎搞?
我刚才看了replace函数的详细说明,好象有点头绪,但是看不太明白。
Replace(expression, find, replacewith[, start[, count[, compare]]]) 

以下是全部替代的办法,寻求替代第二个"aabb"的方法.
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
i = Replace(i, "aabb", "vbgood")
Print #2, i
Loop
Close #1
Close #2

红颜莎娜
浏览 108回答 2
2回答

狐的传说

dim s2 as string,str1 as string,i as stringOpen "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)) + 4s2 = s2 & Left(str1, t) & "vbgood" & Right(str1, Len(str1) - t - 4)Open "c:\text2.ini" For Output As #2 Print #2 , s2close #2

千巷猫影

Open "c:\text1.ini" For Input As #1&nbsp;Open "c:\text2.ini" For Output As #2&nbsp;Dim i As String&nbsp;Do While Not EOF(1)&nbsp;Line Input #1, i&nbsp;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&nbsp;Loop&nbsp;Close #1&nbsp;Close #2经过测试,成功通过!&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP