For reasons I'd rather like to not talk about, I am in a VBA environment that doesn't have the replace function (Access 97). I have wrote this to alleviate my frustrations.
My question is, what is the quickest and most efficient way of writing this function? I am not married to it, I just want the best possible piece of code. While I do enjoy readability I am also OK with stepping away from that to learn something super cool.
Public Function RepStr(InputString As String, InvalidStr As String, ValidStr As String) As String
Dim ModString As String
ModString = InputString
While InStr(1, ModString, InvalidStr) > 0
ModString = Left(ModString, InStr(1, ModString, InvalidStr) - 1) & _
ValidStr & Mid(ModString, Len(InvalidStr) + InStr(1, ModString, InvalidStr))
Wend
RepStr = ModString
End Function
Replace
,InStrRev
,StrReverse
,Join
andSplit
. \$\endgroup\$Replace
function, so that when you eventually migrate from Access 97, you can just delete your shadowing functions, and fall back to the built-in functions. Of course, if you haven't upgraded from Access 97 yet, I suppose you're unlikely to do so in the foreseeable future. Maybe I shouldn't have linked to those functions? Maybe I'm giving you one less reason to upgrade? \$\endgroup\$