FF_REMOVE and FF_REMOVEANY

Started by Paul Squires, August 19, 2015, 01:35:15 PM

Previous topic - Next topic

Paul Squires




''
''  FF_REMOVE
''  Return a copy of a string with characters or strings removed
''
''  If MatchPattern is not present in MainString, all of MainString is returned intact.
''  The replacement can cause MainString to grow or condense in size.
''  This function is case-sensitive.
''
Function FF_Remove( ByRef sMainString   As String, _
                    ByRef sMatchPattern As String _
                    ) As String

    Dim i As Integer
    Dim s As String
   
    If Len(sMainString) = 0 Then Return sMainString

    s = sMainString
    Do
        i = Instr(s, sMatchPattern)
        If i > 0 Then
           s = Left(s, i - 1) & Mid(s, i + Len(sMatchPattern))
        End If   
    Loop Until i = 0
   
    Return s

End Function


''
''  FF_REMOVEANY
''  Return a copy of a string with characters or strings removed
''
''  If MatchPattern is not present in MainString, all of MainString is returned intact.
''  MatchPattern specifies a list of single characters to be searched for individually,
''  a match on any one of which will cause that character to be removed from the result.
''  This function is case-sensitive.
''
Function FF_RemoveAny( ByRef sMainString   As String, _
                       ByRef sMatchPattern As String _
                       ) As String

    If Len(sMainString) = 0 Then Return sMainString
   
    Dim nLenMatch As Integer = Len(sMatchPattern)
    If nLenMatch = 0 Then Return sMainString

    Dim s As String =  sMainString   ' make a default return copy of the string
    Dim i As Integer

    For i = 0 To nLenMatch - 1
       s = FF_Remove( s, Chr(sMatchPattern[i]) )
    Next

    Return s

End Function


Paul Squires
PlanetSquires Software