Function String Replacements Class

StripFirstMatch

Find and remove the first occurrence of one string within another.

Signature (Visual Basic / VBA)

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

Code Example

    StripFirstMatch("This is a test.", "s") = "Thi is a test."
    StripFirstMatch("This is a test.", "1") = "This is a test."
    StripFirstMatch("This is a test.", "") = "This is a test." ' Behavior #3
    StripFirstMatch("This", "s") = ReplaceStringOnce("This", "s", "")

Parameters

Parameter Description
vLine The string in which the first occurrences of vFind is to be removed. Function returns Null if vLine is Null or cannot be fixed up to a String (Behavior #1).
vFind The string which is to be removed from vLine the first time it occurs. 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).
vCompare Specifies the type of comparison used to determine if strings match (Behavior #4). vCompare defaults to Binary comparisons if it is missing or Null or cannot be fixed up to a number (Behavior #5).

Notes & Version History

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.