VB replace函数

来源:百度知道 编辑:UC知道 时间:2024/05/05 05:46:44
大家好:
我有一个.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
我不是非要replace函数不可,达到目的就可以了。

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

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
经过测试,成功通过!