hellothere4
New Member
- Joined
- May 9, 2011
- Messages
- 17
Hello, I'm just looking for a simple way to delete all characters that aren't of the standard type, like a-z, 0-9, .'!? THANKS!!
Function ClearString(ByVal sWord As String) As String
Dim i As Integer
Dim sNewWord As String, sCharacter As String, sPattern As String
Dim re As RegExp, m As Match
sWord = "BCDa%"
sPattern = "[a-z0-9.'!?]"
Set re = New RegExp
With re
.IgnoreCase = True
.Pattern = sPattern
End With
For i = 1 To Len(sWord)
sCharacter = Mid$(sWord, i, 1)
If re.Test(sCharacter) Then
sNewWord = sNewWord & sCharacter
End If
Next
ClearString = sNewWord
End Sub
Function ClearString1(ByVal sWord As String) As String
With CreateObject("VBScript.RegExp")
.Pattern = "[^a-zA-Z0-9.'!?]"
ClearString1 = .Replace(sWord, "")
End With
End Function
Function ClearString2(ByVal sWord As String) As String
Dim i As Integer
Dim sNewWord As String, sCharacter As String, sPattern As String
sPattern = "[a-zA-Z0-9.'!?]"
For i = 1 To Len(sWord)
sCharacter = Mid$(sWord, i, 1)
If sCharacter Like sPattern Then
sNewWord = sNewWord & sCharacter
End If
Next
ClearString2 = sNewWord
End Function
Function RegexRemove(strIn As String)
Dim Regex
Set Regex = CreateObject("vbscript.regexp")
With Regex
.IgnoreCase = True
.Global = True
.Pattern = "[^\w+\s\.\!']"
RegexRemove = .Replace(strIn, vbNullString)
End With
End Function
Function ClearString1(ByVal sWord As String) As String
With CreateObject("VBScript.RegExp")
.Pattern = "[^a-zA-Z0-9.'!?]"
[COLOR=black] .Global = True
[/COLOR] ClearString1 = .Replace(sWord, "")
End With
End Function
...I added a space to the ignore list (/s) and used case ignore and /w in place of a-zA-Z0-9 ...