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

Replace String Function
String Replacements Class

Public Function ReplaceString( _
      ByVal vLine As Variant _
    , ByVal vFind As Variant _
    , Optional ByVal vReplace As Variant _
    , Optional ByVal vCompare As Variant _
    ) As Variant

Perform string replacement.
Replace all non-overlapping occurrences of vFind in vLine with vReplace.

Top20: This function is among our "top-twenty" most useful.
Examples:
    ReplaceString("This is a test.", " ", "-") = "This-is-a-test."
    ReplaceString("This is a test.", "1", "2") = "This is a test."
    ReplaceString("This is a test.", "", "23") = "This is a test." ' Behavior #3
    ReplaceString("This is a test.", " ", "") = "Thisisatest." ' Behavior #5
    ReplaceString("This is a test.", "s", "ss") = "Thiss iss a tesst." ' Behavior #6
See also:
    Replace Function (Visual Basic)
    ReplaceStringFast Function
    ReplaceStringRecursively Function
    ReplaceStringTest Subroutine
    ReplaceStringMultiple Function
    ReplaceStringOnce Function
    ReplaceStringNTimes Function
    ReplaceStringInFile Function
    StrRep Subroutine
vLine: The string in which all occurrences of vFind are to be replaced with vReplace. Function returns Null if vLine is Null or cannot be fixed up to a String (Behavior #1).

vFind: The string which is to be replaced with vReplace wherever it appears within string vLine. Function returns Null if vFind is Null or cannot be fixed up to a String (Behavior #2). Function returns vLine unchanged if vFind is an empty string (Behavior #3).

vReplace: The string which is to replace all occurrences of vFind within string vLine. vReplace defaults to an empty string if it is missing or Null or cannot be fixed up to a String (Behavior #4). vReplace can be an empty string in which case all occurrences of vFind are removed from the string vLine (Behavior #5).

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 #6).

vCompare: Specifies the type of comparison used to determine if strings match (Behavior #7). vCompare defaults to Binary comparisons if it is missing or Null or cannot be fixed up to a number (Behavior #8).

v1.5 Note: This function has been superceded by the Replace function in Visual Basic 6.0. It is similar to the Replace function in Visual Basic, except that this function allows the vFind argument to be Null, in which case it returns Null. Visual Basic's Replace function will generate a runtime error if its Find argument is Null.
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.