Solved

VBscript: Convert to lower case

Posted on 2011-03-19
3
1,365 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
[X]
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
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

749 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