|
|
Очистка текста от спецсимволов
Пример эксплуатации
Private Sub cmdClear_Click()
Dim i%, x%
i = Len(Me!txtTestMemo)
Debug.Print "Было: " & i & " символов."
Me!txtTestMemo = ClearString(Me!txtTestMemo)
x = Len(Me!txtTestMemo)
Debug.Print "Стало:" & x & " символов."
Debug.Print "Разница (удалено): " i - x & " символов."
End Sub
Функция:
Public Function ClearString(vVal As Variant) As Variant
Dim iVal As Integer
Dim iAsc As Integer
Dim sOne As String * 1
Dim iLen As Integer
Dim strReturn As String
Dim strTemp As String
On Error GoTo ClearString_Err
strReturn = Trim(vbNullString & vVal)
strTemp = strReturn
strReturn = Replace(strTemp, vbCr, " ")
strTemp = strReturn
strReturn = Replace(strTemp, vbLf, " ")
For iVal = 1 To 3
strTemp = strReturn
strReturn = Replace(strTemp, " ", " ")
Next iVal
strTemp = strReturn
strReturn = ""
iLen = Len(strTemp)
For iVal = 1 To iLen
sOne = Mid(strTemp, iVal, 1)
iAsc = Asc(sOne)
Select Case iAsc
Case 0 To 31: sOne = vbNullString
Case 127 To 129: sOne = vbNullString
Case 140 To 144: sOne = vbNullString
Case 145 To 146: sOne = vbNullString
Case 147 To 148: sOne = Chr(34)
Case 149: sOne = vbNullString
Case 150 To 151: sOne = Chr(45)
Case 152 To 160: sOne = vbNullString
Case 161 To 167: sOne = vbNullString
Case 168:
Case 169, 170: sOne = vbNullString
Case 171: sOne = Chr(34)
Case 172: sOne = vbNullString
Case 173:
Case 174 To 183: sOne = vbNullString
Case 184:
Case 185, 186:
Case 187: sOne = Chr(34)
Case 188 To 191: sOne = vbNullString
End Select
strReturn = strReturn & sOne
Next iVal
ClearString = strReturn
ClearString_End:
Exit Function
ClearString_Err:
ClearString = vVal
Err.Clear
Resume ClearString_End
End Function
|
|