Solved

VBscript: Convert to lower case

Posted on 2011-03-19
3
1,352 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
Comment Utility
Line 50 can simply be changed to use the LCase function...

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

Author Comment

by:ReneGe
Comment Utility
It works.

Thanks sirbounty!

Cheers,
Rene
0
 
LVL 67

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now