<-- Previous || Up || Next -->

Replace String Fast Function
String Replacements Class

Public Function ReplaceStringFast( _
      ByRef vLine As String _
    , ByRef vFind As String _
    , ByRef vReplace As String _
    , ByRef vCompare As VbCompareMethod _
    ) As String

Perform string replacement.
Replace all non-overlapping occurrences of vFind in vLine with vReplace.
Faster version of the ReplaceString function which uses restrictive argument types to avoid argument fix-up code.

Examples:
    ReplaceStringFast("This is a test.", " ", "-", vbTextCompare) = "This-is-a-test."
    ReplaceStringFast("This is a test.", "1", "2", vbTextCompare) = "This is a test."
    ReplaceStringFast("This is a test.", "", "23", vbTextCompare) = "This is a test." ' Behavior #1
    ReplaceStringFast("This is a test.", " ", "", vbTextCompare) = "Thisisatest." ' Behavior #2
    ReplaceStringFast("This is a test.", "s", "ss", vbTextCompare) = "Thiss iss a tesst." ' Behavior #3
See also:
    Replace Function (Visual Basic)
    ReplaceString Function
    ReplaceStringRecursively Function
Note: This function works correctly with vReplace strings that contain the vFind string. For example, Chr$(10) can be replaced by Chr$(10)+Chr$(13) without the function getting stuck in an infinite loop.

vLine: The string in which all occurrences of vFind are to be replaced with vReplace.
vFind: The string which is to be replaced with vReplace wherever it appears within string vLine. Function returns vLine unchanged if vFind is an empty string (Behavior #1).
vReplace: The string which is to replace all occurrences of vFind within string vLine. vReplace can be an empty string in which case all occurrences of vFind are removed from the string vLine (Behavior #2).
Note: This function works correctly with vReplace strings that contain the vFind string. For example, Chr$(10) can be replaced by Chr$(10)+Chr$(13) without the function getting stuck in an infinite loop (Behavior #3).
vCompare: Specifies the type of comparison used to determine if strings match (Behavior #4).
v1.1 BugFix: Changed the type of the first three arguments from Variant to String.
v1.5 Note: This function has been superceded by the Replace function in Visual Basic 6.0.
v1.5 Pro Change: The implementation of this function has been changed to use the Replace function in Visual Basic.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.