Difference between revisions of "Microsoft Access modString"

From database24
Jump to navigation Jump to search
Line 92: Line 92:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== matches ===
+
=== matchesRegEx ===
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
Public Function matches(strString As String, strRegEx As String, Optional blnIgnoreCase As Boolean = False) As Boolean
+
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 110:
 
     End With
 
     End With
 
   
 
   
     matches = blnResult
+
     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
 +
        .IgnoreCase = blnIgnoreCase
 +
        .Pattern = strFromRegEx
 +
        strResult = .Replace(strSource, strToRegEx)
 +
    End With
 +
   
 +
    replaceRegEx = strResult
 
End Function
 
End Function
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 23:46, 13 July 2010

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

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
        .IgnoreCase = blnIgnoreCase
        .Pattern = strFromRegEx
        strResult = .Replace(strSource, strToRegEx)
    End With
    
    replaceRegEx = strResult
End Function