Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBscript: Convert to lower case

Posted on 2011-03-19
3
1,362 Views
Last Modified: 2012-06-27
Hi there,

In the following script, I need to convert the extracted emails to lower case.

Thanks for your help,
Rene

 
Option Explicit

Dim objArgs, fso, strFile, strTestString
Dim strEmailPattern, strTelFaxPattern, strAllMatches

Set objArgs = WScript.Arguments

ErrCheck objArgs.Count < 1, 1, "No argument specified."

strFile = objArgs(0)

Set fso = CreateObject("Scripting.FileSystemObject")
ErrCheck Not fso.FileExists(strFile), 1, "File supplied as argument cannot be found: '" & strFile & "'"

'# WScript.Echo "Checking file contents for email addresses: '" & strFile & "'" & vbCrlf

strEmailPattern = "([\w-\.]+)@[\w-]{2,}(\.[\w-]{2,}){1,5}"
strTelFaxPattern = "((copieur|fax)?(?:[^A-Za-z0-9\n\r\t]*))?\(?(\d{3})\)?[- \.]?(\d{3})[- \.]?(\d{4})"

strTestString = fso.OpenTextFile(strFile, 1).ReadAll
strTestString = Replace(strTestString, "&nbsp", " ")

strAllMatches = fGetEmailMatches(strEmailPattern, strTestString)
If strAllMatches <> "" Then strAllMatches = strAllMatches & vbCrlf
strAllMatches = strAllMatches & fGetTelFaxMatches(strTelFaxPattern, strTestString)

If strAllMatches <> "" Then
    WScript.Echo strAllMatches
Else
    WScript.Echo "NoInfo"
End If

'# WScript.Echo vbCrlf & "End of " & WScript.ScriptName



Function fGetEmailMatches(sPattern, sStr)
    Dim regEx, retVal, oMatch, colMatches, temp
    Set regEx = New RegExp     ' Create a regular expression.
    regEx.Pattern = sPattern   ' Set pattern.
    regEx.IgnoreCase = True   ' Set case insensitivity.
    regEx.Global = True        ' Set global applicability.

    Set colMatches = regEx.Execute(sStr)   ' Execute search.

    If colMatches.Count = 0 Then
        temp = ""
    Else
        For Each oMatch In colMatches
            temp = temp & "email:" & oMatch & "¶"
        Next
        temp = Left(temp, Len(temp) - 1)
        temp = Replace(temp, "¶", vbCrlf)
    End If
   fGetEmailMatches = temp
End Function

Function fGetTelFaxMatches(sPattern, sStr)
    Dim regEx, retVal, oMatch, colMatches, temp, sPrefix
    Set regEx = New RegExp     ' Create a regular expression.
    regEx.Pattern = sPattern   ' Set pattern.
    regEx.IgnoreCase = True   ' Set case insensitivity.
    regEx.Global = True        ' Set global applicability.

    Set colMatches = regEx.Execute(sStr)   ' Execute search.

    If colMatches.Count = 0 Then
        temp = ""
    Else
        For Each oMatch In colMatches
            sPrefix = "phone:"
            If LCase(Left(oMatch, 3)) <> "fax" And LCase(Left(oMatch, 7)) <> "copieur" Then
                temp = temp & sPrefix & oMatch.SubMatches(2) & "-" & oMatch.SubMatches(3) & "-" & oMatch.SubMatches(4) & "¶"
            End If
        Next
        For Each oMatch In colMatches
            sPrefix = "fax:"
            If LCase(Left(oMatch, 3)) = "fax" Or LCase(Left(oMatch, 7)) = "copieur" Then
                temp = temp & sPrefix & oMatch.SubMatches(2) & "-" & oMatch.SubMatches(3) & "-" & oMatch.SubMatches(4) & "¶"
            End If
        Next

        temp = Left(temp, Len(temp) - 1)
        temp = Replace(temp, "¶", vbCrlf)

    End If



    fGetTelFaxMatches = temp
End Function



Sub ErrCheck(blTest, iErrNum, sTxt)
    Dim sErrText
    If Not blTest Then Exit Sub
    sErrText = "Error: " & sTxt
    MsgBox sErrText, vbSystemModal + vbCritical, "Error in: " & WScript.ScriptName
    WScript.Quit iErrNum
End Sub

Open in new window


0
Comment
Question by:ReneGe
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 35174027
Line 50 can simply be changed to use the LCase function...

 temp = temp & "email:" & lCase(oMatch) & "¶"
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35174090
It works.

Thanks sirbounty!

Cheers,
Rene
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 35175068
Happy to have helped - thanks for the grade! :^)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This is about my first experience with programming Arduino.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question