Difference between revisions of "Microsoft Access modString"
Jump to navigation
Jump to search
(3 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 92: | Line 96: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === | + | |
+ | == Regular Expression == | ||
+ | |||
+ | === matchesRegEx === | ||
<syntaxhighlight lang="vb"> | <syntaxhighlight lang="vb"> | ||
− | Public Function | + | Public Function matchesRegEx( _ |
+ | strString As String, _ | ||
+ | strRegEx As String, _ | ||
+ | Optional blnIgnoreCase As Boolean = False _ | ||
+ | ) As Boolean | ||
Dim blnResult As Boolean | Dim blnResult As Boolean | ||
Line 106: | Line 117: | ||
End With | End With | ||
− | + | matchesRegEx = blnResult | |
+ | End Function | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === replaceRegEx === | ||
+ | <syntaxhighlight lang="vb"> | ||
+ | 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 | End Function | ||
</syntaxhighlight> | </syntaxhighlight> |
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