Dim strAll As String Dim lngPosition As LongstrAll = "########(###(####)##)###"lngPosition = InStr(1, strAll, "(") Do While lngPosition > 0 strAll = Replace(strAll, "(", "【 ") lngPosition = InStr(1, strAll, "(") Loop lngPosition = InStr(1, strAll, ")") Do While lngPosition > 0 strAll = Replace(strAll, ")", "】 ") lngPosition = InStr(1, strAll, ")") LoopMsgBox strAll
dim strsearch as stringdo while instr(strsearch,"(")<>0 strsearch=replace(strsearch,"(","【") loopdo while instr(strsearch,")")<>0 strsearch=replace(strsearch,"(","】") loop
Private Sub Command1_Click() Dim strAll As String Dim strAll1 As String Dim strall2 As String Dim lngPosition As Long Dim No As Long strAll = "##(#(#####(###(##)##)##)#)##"lngPosition = InStr(1, strAll, "(") strAll1 = Right(strAll, Len(strAll) - lngPosition) strall2 = Left(strAll, lngPosition)Do While lngPosition > 0 No = No + 1 strAll1 = Replace(strAll1, "(", "【 ", , 1) lngPosition = InStr(1, strAll1, "(") Loop Debug.Print strAll1, No strAll = strall2 + strAll1 lngPosition = InStr(1, strAll, ")") Do While lngPosition > 0 If No < 1 Then Exit Do End If strAll = Replace(strAll, ")", "】 ", , 1) lngPosition = InStr(1, strAll, ")") No = No - 1 LoopMsgBox strAll End Sub
Dim strAll As String Dim lngPosition As Long Dim lngStart As Long Dim lngEnd As Long
Dim lngPosition As LongstrAll = "########(###(####)##)###"lngPosition = InStr(1, strAll, "(")
Do While lngPosition > 0
strAll = Replace(strAll, "(", "【 ")
lngPosition = InStr(1, strAll, "(")
Loop
lngPosition = InStr(1, strAll, ")")
Do While lngPosition > 0
strAll = Replace(strAll, ")", "】 ")
lngPosition = InStr(1, strAll, ")")
LoopMsgBox strAll
strsearch=replace(strsearch,"(","【")
loopdo while instr(strsearch,")")<>0
strsearch=replace(strsearch,"(","】")
loop
Dim strAll As String
Dim strAll1 As String
Dim strall2 As String
Dim lngPosition As Long
Dim No As Long
strAll = "##(#(#####(###(##)##)##)#)##"lngPosition = InStr(1, strAll, "(")
strAll1 = Right(strAll, Len(strAll) - lngPosition)
strall2 = Left(strAll, lngPosition)Do While lngPosition > 0
No = No + 1
strAll1 = Replace(strAll1, "(", "【 ", , 1)
lngPosition = InStr(1, strAll1, "(")
Loop
Debug.Print strAll1, No
strAll = strall2 + strAll1
lngPosition = InStr(1, strAll, ")")
Do While lngPosition > 0
If No < 1 Then
Exit Do
End If
strAll = Replace(strAll, ")", "】 ", , 1)
lngPosition = InStr(1, strAll, ")")
No = No - 1
LoopMsgBox strAll
End Sub
Dim lngPosition As Long
Dim lngStart As Long
Dim lngEnd As Long
strAll = "########2(2###(####)##3)3###"
'记下第一个(位置
lngStart = InStr(1, strAll, "(")
lngPosition = InStr(1, strAll, ")")
Do While lngPosition > 0
'记下最后一个)位置
lngEnd = lngPosition
lngPosition = InStr(lngEnd + 1, strAll, ")")
Loop
lngPosition = InStr(1, strAll, "(")
Do While lngPosition > 0
strAll = Replace(strAll, "(", "【")
lngPosition = InStr(1, strAll, "(")
Loop
lngPosition = InStr(1, strAll, ")")
Do While lngPosition > 0
strAll = Replace(strAll, ")", "】")
lngPosition = InStr(1, strAll, ")")
Loop
MsgBox strAll
'全部替换后,再把前面相应记下的位置换成你要用的符号
MsgBox Left(strAll, lngStart - 1) & "(" & Mid(strAll, lngStart + 1, lngEnd - lngStart - 1) & ")" & Mid(strAll, lngEnd + 1)
或者用记住的位置把原串分成三个子串,然后只对中间的子串进行替换,再合成一个整串.