One way is to use an ArrayList
.
Not sure what you want to replace the matched item with. In the code below, it is being replaced with the sequence number, which matches what you describe, but may not be what you really want.
Option Explicit
Sub due()
Const str1 As String = "A25+F47+w41+r21+h65"
Const str2 As String = "4+7+4+4+2"
Const strMatch As String = "w41"
Dim AL As Object
Dim v, w, I As Long
Set AL = CreateObject("System.Collections.ArrayList")
'put str2 into arrayList
v = Split(str2, "+")
For Each w In v
AL.Add w
Next w
'Check str1 against matchStr to get positions and act on the item in AL at that position
v = Split(str1, "+")
For I = 0 To UBound(v)
'Note that arrayList index and "Split" array are zero-based
If strMatch = v(I) Then
AL.removeat I 'remove item in the same position as the position of the matched item
AL.Insert I, I + 1 'Insert new item at that same position. Could be anything. I chose I+1 to match what you wrote in your question.
End If
Next I
Debug.Print Join(AL.toarray, "+")
End Sub
=> 4+7+3+4+2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…