Ultra Fast String Replace Function (Optimized Loop)
Custom string replace function designed for high-performance scenarios. Outperforms VB Replace() in large loops by minimizing reallocations.
Rate Ultra Fast String Replace Function (Optimized Loop)
(0(0 Vote))
Public Function FastReplace(ByVal sText As String, ByVal sFind As String, ByVal sReplace As String) As String
Dim lPos As Long, lStart As Long
Dim sOut As String
lStart = 1
Do
lPos = InStr(lStart, sText, sFind)
If lPos = 0 Then Exit Do
sOut = sOut & Mid$(sText, lStart, lPos - lStart) & sReplace
lStart = lPos + Len(sFind)
Loop
sOut = sOut & Mid$(sText, lStart)
FastReplace = sOut
End Function
'Usage:
'MsgBox FastReplace("hello world", "world", "VB6")
Ultra Fast String Replace Function (Optimized Loop) Comments
No comments yet — be the first to post one!
Post a Comment