Difference between revisions of "Microsoft Access modString"
Jump to navigation
Jump to search
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Microsoft Access]] | ||
+ | [[Category:VBA]] | ||
+ | == String == | ||
+ | |||
=== getAlNumString === | === getAlNumString === | ||
<syntaxhighlight lang="vb"> | <syntaxhighlight lang="vb"> | ||
Line 91: | Line 95: | ||
End Function | End Function | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | == Regular Expression == | ||
=== matchesRegEx === | === matchesRegEx === | ||
Line 128: | Line 135: | ||
Set rgx = New RegExp | Set rgx = New RegExp | ||
With rgx | With rgx | ||
+ | .Global = True | ||
.IgnoreCase = blnIgnoreCase | .IgnoreCase = blnIgnoreCase | ||
.Pattern = strFromRegEx | .Pattern = strFromRegEx |
Latest revision as of 10:15, 22 July 2010
String
getAlNumString
Public Function getAlNumString(strSource As String) As String
Dim strResult As String
Dim intIndex As Integer
Dim strCharacter As String
strResult = ""
For intIndex = 1 To Len(strSource)
strCharacter = Mid(strSource, intIndex, 1)
Select Case Asc(strCharacter)
''A - Z, a - z
Case 65 To 90, 97 To 122
strResult = strResult & strCharacter
'0 - 9
Case 48 To 57
strResult = strResult & strCharacter
Case Else
'nothing
End Select
Next
getAlNumString = strResult
End Function
getAlNumPunctString
Public Function getAlNumPunctString(strSource As String) As String
Dim strResult As String
Dim intIndex As Integer
Dim strCharacter As String
strResult = ""
For intIndex = 1 To Len(strSource)
strCharacter = Mid(strSource, intIndex, 1)
Select Case Asc(strCharacter)
'A - Z, a - z
Case 65 To 90, 97 To 122
strResult = strResult & strCharacter
'0 - 9
Case 48 To 57
strResult = strResult & strCharacter
'<space>, <comma>, <hyphen>, <dot>, <slash>
Case 20, 44 To 47
strResult = strResult & strCharacter
Case Else
'nothing
End Select
Next
getAlNumPunctString = strResult
End Function
getPrintableString
Public Function getPrintableString(strSource As String) As String
Dim strResult As String
Dim intIndex As Integer
Dim strCharacter As String
strResult = ""
For intIndex = 1 To Len(strSource)
strCharacter = Mid(strSource, intIndex, 1)
Select Case Asc(strCharacter)
'ASCII printable characters
Case 20 To 126
strResult = strResult & strCharacter
Case Else
'nothing
End Select
Next
getPrintableString = strResult
End Function
Regular Expression
matchesRegEx
Public Function matchesRegEx( _
strString As String, _
strRegEx As String, _
Optional blnIgnoreCase As Boolean = False _
) As Boolean
Dim blnResult As Boolean
Dim rgx As RegExp
Set rgx = New RegExp
With rgx
.IgnoreCase = blnIgnoreCase
.Pattern = strRegEx
blnResult = .Test(strString)
End With
matchesRegEx = blnResult
End Function
replaceRegEx
Public Function replaceRegEx( _
strSource As String, _
strFromRegEx As String, _
strToRegEx As String, _
Optional blnIgnoreCase As Boolean = False _
) As String
Dim strResult As String
Dim rgx As RegExp
Set rgx = New RegExp
With rgx
.Global = True
.IgnoreCase = blnIgnoreCase
.Pattern = strFromRegEx
strResult = .Replace(strSource, strToRegEx)
End With
replaceRegEx = strResult
End Function