Parsing names
Thank you Ron! I was wondering if I could do this with regular
expressions as well.
"Ron Rosenfeld" wrote in message
...
You could use regular expressions to parse the word, and put each part
into one of your variables. Note in the regex the "pipe-separated list"
of allowable titles. You may need to add to this.
=====================
Sub NameParts()
Dim re As Object, mc As Object
Dim s As String
Dim myLast As String
Dim myTitle As String
Dim myFirst As String
Dim myMiddle As String
Set re = CreateObject("vbscript.regexp")
re.Pattern =
"^(\w+)\s+(?:(Jr|Sr|III|II|IV)\s+)?(?:(\w\w+)\s+)( ?:([A-Z])\s+)?"
re.Global = True
re.ignorecase = True
s = MyVar1
If re.test(s) = True Then
Set mc = re.Execute(s)
myLast = mc(0).submatches(0)
myTitle = mc(0).submatches(1)
myFirst = mc(0).submatches(2)
myMiddle = mc(0).submatches(3)
End If
End Sub
===============================
|