As an addendum to that, and only for anyone interested in such things, I actually find that I use the Replace() technique so much that I even wrote a function to handle multiple pairs of parameters for replacing.
I have to replace any posted code with multiple calls to Replace() so that it makes sense generally in the forums.
I have to replace any posted code with multiple calls to Replace() so that it makes sense generally in the forums.
Code:
'MultiReplace replaces all occurrences of varParam in strMain with varReplace. 'Using VbBinaryCompare means that case is not ignored. Public Function MultiReplace(ByRef strMain As String, _ ByVal varParam As Variant, _ ByVal varReplace As Variant, _ ParamArray avarArgs()) Dim intIdx As Integer If (UBound(avarArgs) - LBound(avarArgs)) Mod 2 = 0 Then Stop MultiReplace = Replace(Expression:=strMain, _ Find:=Nz(varParam, ""), _ Replace:=Nz(varReplace, ""), _ Compare:=vbBinaryCompare) For intIdx = LBound(avarArgs) To UBound(avarArgs) Step 2 MultiReplace = Replace(Expression:=MultiReplace, _ Find:=Nz(avarArgs(intIdx), ""), _ Replace:=Nz(avarArgs(intIdx + 1), ""), _ Compare:=vbBinaryCompare) Next intIdx End Function
Comment