|
|
Joined: Dec 1999
Posts: 30,867
Master Elite Member
|
Public Function SArr_PurgeStr(SArray() As String, MyString As String, CaseSen As Boolean) As String()
'Function
' Removes all instances of a specified string (MyString) from a string array (SArray).
'Parameters
' SArray (String()) = The array to filter.
' MyString (String) = The string to remove from SArray.
' CaseSen (Boolean) = If True, the comparison is case-sensitive.
' If False, the comparison is not case-sensitive.
'Return
' Returns a string array containing all the elements in SArray except any elements that match MyString.
' Returns an empty array if:
' SArray is empty.
' Returns all the elements in SArray if:
' MyString is not found in SArray.
'Version History
' 1.0 4/1/2006 8am Tested by Russ Tanner on VB6 Win2000
'---
'Initiate variables
Dim i As Long 'index into SArray
Dim R() As String 'return buffer
'Trap: The source array is empty, always return an empty array
If ElementCount(SArray) = 0 Then
SArr_PurgeStr = R
Exit Function
End If
'Loop though all elements in SArray...
'The search is case-sensitive
If CaseSen Then
For i = LBound(SArray) To UBound(SArray)
'Match not found, append this element to the return buffer
If SArray(i) <> MyString Then
ReDim Preserve R(ElementCount(R))
R(UBound(R)) = SArray(i)
End If
Next i
'The search is not case-sensitive
Else
For i = LBound(SArray) To UBound(SArray)
'Match not found, append this element to the return buffer
If UCase(SArray(i)) <> UCase(MyString) Then
ReDim Preserve R(ElementCount(R))
R(UBound(R)) = SArray(i)
End If
Next i
End If
'Return the result
SArr_PurgeStr = R
End Function
|
|
|
|
Entire Thread
|
Removes all instances of a specified string (MyString) from a string array (SArray).
|
Russ
|
08/11/08 10:29 PM
|
|
|
|