|
|
Очистка строки от "мусора" по списку, переданному через массив
Пример использования функции:
Dim i%, s$
Dim ch() As Variant
i = CInt(TB_SelLength)
If i > 30 Then i = 30
s = Mid(Me!txtTextField, 1, i)
ch = Array(vbCrLf, ".", ",", ":", ";", "?", "!", "(", ")", " ")
Me!txtSearch = CleanStrByArray(s, ch, " ")
Функция:
Public Function CleanStrByArray(sString$, vArr() As Variant, Optional sReplace$ = "") As String
Dim i%, sSearch$, sReturn$
On Error GoTo CleanStrByArray_Err
sReturn = sString
For i = LBound(vArr) To UBound(vArr)
sSearch = vArr(i)
sReturn = Replace(sReturn, sSearch, sReplace, 1)
Next i
CleanStrByArray = Trim(sReturn)
CleanStrByArray_Bye:
Exit Function
CleanStrByArray_Err:
CleanStrByArray = ""
MsgBox "Ошибка " & Err.Number & vbCrLf & Err.Description & vbCrLf & "в процедуре: CleanStrByArray", vbCritical, "Error in module modSearchInTextBox"
Resume CleanStrByArray_Bye
End Function
|
|