You should know that multiple titles usually aren't seperated by spaces (i.e: Mr.Ir. A.B. Smith). I once wrote a parsing function like this:
Private Sub ParseContact(ByVal vcurFieldIndex As Currency, ByRef rstrContact As String)
Dim intCounter As Integer, intPos As Integer, aintPos() As Integer, intInnerCounter As Integer, intTemp As Integer
Dim strContact As String, astrTitle() As String, strOrgVal As String, strGender As String, strTemp As String, strTitle As String, strMiddle As String
On Error GoTo ErrHandler
Select Case vcurFieldIndex
Case FIELD_CNT_GENDER, FIELD_CNT_INITIALS, FIELD_CNT_TITLE
intPos = InStrRev(rstrContact, "."

'//The last decimal point terminates the titles/initials section of the contact information.
If intPos > 0 Then '//However, one column does not provide this.
'//Filter out title stuff:
strContact = left(rstrContact, intPos)
strOrgVal = strContact
For intCounter = LBound(m_astrTitles, 1) To UBound(m_astrTitles, 1)
intPos = InStr(1, strContact, m_astrTitles(intCounter, TITLE_TITLE), vbTextCompare)
If intPos > 0 Then
'//Save position of this title:
Add2Array_Integer aintPos, InStr(1, strOrgVal, m_astrTitles(intCounter, TITLE_TITLE), vbTextCompare), False
'//Add to titles array and remove from string:
Add2Array_String astrTitle, Mid(strContact, intPos, Len(m_astrTitles(intCounter, TITLE_TITLE))), False
strContact = Trim(Replace(strContact, astrTitle(UBound(astrTitle)), "", 1, 1, vbTextCompare))
'//Save gender:
If m_astrTitles(intCounter, TITLE_GENDER) <> "O" Then strGender = m_astrTitles(intCounter, TITLE_GENDER)
End If
Next intCounter
If TestArray_String(astrTitle) Then
'//Set titles in correct order:
For intCounter = UBound(aintPos) - 1 To 0 Step -1
For intInnerCounter = 0 To intCounter
If aintPos(intInnerCounter) > aintPos(intInnerCounter + 1) Then
intTemp = aintPos(intInnerCounter + 1)
strTemp = astrTitle(intInnerCounter + 1)
aintPos(intInnerCounter + 1) = aintPos(intInnerCounter)
aintPos(intInnerCounter) = intTemp
astrTitle(intInnerCounter + 1) = astrTitle(intInnerCounter)
astrTitle(intInnerCounter) = strTemp
End If
Next intInnerCounter
Next intCounter
strTitle = Join(astrTitle, Chr(32))
End If
rstrContact = Trim(CStr(Switch(vcurFieldIndex = FIELD_CNT_GENDER, strGender, _
vcurFieldIndex = FIELD_CNT_TITLE, strTitle, _
vcurFieldIndex = FIELD_CNT_INITIALS, strContact)))
ElseIf vcurFieldIndex = FIELD_CNT_GENDER Then '//And in this case, we only need to parse out the gender.
For intCounter = LBound(m_astrTitles, 1) To UBound(m_astrTitles, 1)
If StrComp(m_astrTitles(intCounter, TITLE_TITLE), rstrContact, vbTextCompare) = 0 Then Exit For
Next intCounter
If intCounter <= UBound(m_astrTitles, 1) Then
rstrContact = m_astrTitles(intCounter, TITLE_GENDER)
Else
rstrContact = ""
End If
End If
Case FIELD_CNT_MIDDLE, FIELD_CNT_LAST
'//Start after initials:
strContact = Trim(Mid(rstrContact, InStrRev(rstrContact, "."

+ 1))
'//See if a middle name can be parsed out:
For intCounter = 1 To m_colMiddleNames.Count
If StrComp(left(strContact, Len(CStr(m_colMiddleNames.Item(intCounter) & " "

)), CStr(m_colMiddleNames.Item(intCounter) & " "

, vbTextCompare) = 0 Then
strMiddle = left(strContact, Len(CStr(m_colMiddleNames.Item(intCounter))))
strContact = Trim(Mid(strContact, Len(strMiddle) + 1))
Exit For
End If
Next intCounter
rstrContact = Trim(CStr(IIf(vcurFieldIndex = FIELD_CNT_MIDDLE, strMiddle, strContact)))
End Select
On Error GoTo 0
Exit Sub
ErrHandler:
'//Show error:
g_objApp.DoUnexpectedError "clsChamberOfCommerce", "ParseContact"
End Sub
---------------------------------------------------------
And this is how the Arrays with middlenames and titles look. As you'll see they're far from complete (and they're strictly Dutch orientated)....
'//Fill middlenames collection with values:
Set m_colMiddleNames = New Collection
With m_colMiddleNames
.Add "van het"
.Add "van 't"
.Add "van der"
.Add "van den"
.Add "van de"
.Add "van"
.Add "v/d"
.Add "de"
.Add "der"
.Add "den"
.Add "op 't"
.Add "op de"
.Add "op het"
.Add "in 't"
.Add "in het"
.Add "in de"
.Add "in den"
.Add "ten"
.Add "ter"
.Add "te"
.Add "'t"
End With
'//Fill titles collection with values:
ReDim m_astrTitles(10, 1)
m_astrTitles(0, TITLE_TITLE) = "MR."
m_astrTitles(0, TITLE_GENDER) = "O"
m_astrTitles(1, TITLE_TITLE) = "DE HEER"
m_astrTitles(1, TITLE_GENDER) = "M"
m_astrTitles(2, TITLE_TITLE) = "MEVROUW"
m_astrTitles(2, TITLE_GENDER) = "V"
m_astrTitles(3, TITLE_TITLE) = "DRS."
m_astrTitles(3, TITLE_GENDER) = "O"
m_astrTitles(4, TITLE_TITLE) = "ING."
m_astrTitles(4, TITLE_GENDER) = "O"
m_astrTitles(5, TITLE_TITLE) = "IR."
m_astrTitles(5, TITLE_GENDER) = "O"
m_astrTitles(6, TITLE_TITLE) = "DR."
m_astrTitles(6, TITLE_GENDER) = "O"
m_astrTitles(7, TITLE_TITLE) = "JONKHEER"
m_astrTitles(7, TITLE_GENDER) = "M"
m_astrTitles(8, TITLE_TITLE) = "JONKVROUW"
m_astrTitles(8, TITLE_GENDER) = "M"
m_astrTitles(9, TITLE_TITLE) = "DE WELEDELGESTRENGE HEER"
m_astrTitles(9, TITLE_GENDER) = "M"
m_astrTitles(10, TITLE_TITLE) = "DE WELEDELGESTRENGE VROUW"
m_astrTitles(10, TITLE_GENDER) = "V"
'//Fill letter headings collection with values:
ReDim m_astrHeadings(1, 1)
m_astrHeadings(0, TITLE_TITLE) = "GEACHTE HEER"
m_astrHeadings(0, TITLE_GENDER) = "M"
m_astrHeadings(1, TITLE_TITLE) = "GEACHTE MEVROUW"
m_astrHeadings(1, TITLE_GENDER) = "V"
Greetings,
Rick