Dim s As String, find As String
s = "123:abc:345:aaa:www:xyz:123"
'比如我们要修改www为eee
find = Split(s, ":")(4)
s = Replace(s, find, "eee")
MsgBox s
s = "123:abc:345:aaa:www:xyz:123"
'比如我们要修改www为eee
find = Split(s, ":")(4)
s = Replace(s, find, "eee")
MsgBox s
n = Val(txtConlon_Number) - 1
Open "1.txt" For Input As #1
Open "2.txt" For Output As #2
Do Until EOF(1)
Line Input #1, strLine
If InStr(strLine, txtMachine_Type) Then
strItem = Split(strLine, ":")
If n <= Ubound(strItem) Then strItem(n) = txtNew_Data
strLine = Join(strItem, ":")
End If Print #2, strLine
Loop
Close #2
Close #1
2.txt 就是修改后的文件。
注意,不要用 Replace 替换行文本。因为行中如果有与第 4 和第 5 个引号之间相同的内容,都会被替换掉。例如,这两个引号之间是 "1",那么这一行中所有的 "1" 都将被替换掉。直接改掉分割后的该项目就可以了。