Function String Searches Class

LeftOfFirstMatch

Return the portion of vLine before the first occurrence of vFind, else return vIfNotFound. If a match is found, it does not include the matching text in the string that is returned.

Signature (Visual Basic / VBA)

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

Code Example

    LeftOfFirstMatch("This is a test.", "is") = "Th"
    LeftOfFirstMatch("This is a test.", "sample") = "This is a test."
    LeftOfFirstMatch("This is a test.", "sample", Null, "Not found.") = "Not found."
    LeftOfFirstMatch("This is a test.", "") = ""

Parameters

Parameter Description
vLine The string which is to be searched from left-to-right for the appearance of string vFind. Function returns Null if vLine is Null or cannot be fixed up to a String.
vFind The string which is to be searched for within string vLine. Function returns Null if vFind is Null or cannot be fixed up to a String. Function returns an empty string if vFind is an empty string.
vCompare Specifies the type of comparison used to determine if strings match. vCompare defaults to Binary comparisons if it is missing or Null or cannot be fixed up to a number.
vIfNotFound The string which is to be returned if vFind does not appear within vLine. vIfNotFound defaults to vLine (i.e. the string is returned unchanged) if it is missing or Null or cannot be fixed up to a String.