PlanetSquires Forums

Support Forums => General Board => Topic started by: Paul Squires on August 19, 2015, 01:35:15 PM

Title: FF_REMOVE and FF_REMOVEANY
Post by: Paul Squires on August 19, 2015, 01:35:15 PM



''
''  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