PlanetSquires Forums

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

Title: FF_RETAIN and FF_RETAINANY
Post by: Paul Squires on August 19, 2015, 01:45:12 PM



''
''  FF_RETAIN
''  Return a string containing only the characters contained in a specified
''  match string. All other characters are removed.
''
''  If MatchPattern is an empty string the function returns an empty string.
''  This function is case-sensitive.
''
Function FF_Retain( ByRef sMainString   As String, _
                    ByRef sMatchPattern As String _
                    ) As String

    Dim nLenMatch As Integer = Len(sMatchPattern)
    If nLenMatch = 0 Then Return ""
   
    Dim i As Integer = 1
    Dim s As String
   
    Do
        i = Instr(i, sMainString, sMatchPattern)
        If i > 0 Then
           s = s & Mid(sMainString, i, Len(sMatchPattern))
           i = i + Len(sMatchPattern)
        End If   
    Loop Until i = 0
   
    Return s

End Function


''
''  FF_RETAINANY
''  Return a string containing only the characters contained in a specified
''  match string. All other characters are removed.
''
''  If MatchPattern is an empty string the function returns an empty string.
''  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_RetainAny( ByRef sMainString   As String, _
                       ByRef sMatchPattern As String _
                       ) As String

    Dim nLenMain  As Integer = Len(sMainString)
    Dim nLenMatch As Integer = Len(sMatchPattern)
    If nLenMatch = 0 Then Return ""
   
    Dim y     As Integer = 1
    Dim i     As Integer = 1
    Dim sChar As String
    Dim s     As String
   
    For y = 1 To Len(sMainString)     
        sChar = Mid(sMainString, y, 1)
        i = Instr( sMatchPattern, sChar )
        If i > 0 Then s = s & sChar
    Next
   
    Return s

End Function