Proper capitalization for surname like McDonald

I am using the code below to capitalize a string properly. I would like to know if there is a better way to code the surname portion, as the way it stands now can become very bloated depending on how many surnames I plan on adding.

This is a follow up to: Capitalize string except for conjunction words

Dim conjunctions
Dim suffixes
Dim surnames
Set conjunctions = CreateObject("System.Collections.Arraylist")
Set suffixes = CreateObject("System.Collections.Arraylist")
Set surnames = CreateObject("System.Collections.Arraylist")

' etc....

for each item in xTextSplit
xWord = item
if conjunctions.contains(lcase(item)) then
xWord = lcase(item)
elseif suffixes.contains(lcase(item)) then
xWord = ucase(item)
elseif surnames.contains(lcase(item)) then
xWord = "Mc" & UCase(Mid(item, 3, 1)) & Mid(item, 4)
end if
xCompleteWord = xCompleteWord & " " & xWord
next


• this is a really good question. what if you have something like O'neill or other prefixes as well?
– Malachi
May 15 '14 at 21:33
• this really depends on where you are getting the information and what you are going to be doing with the information. I would probably try writing the code out and seeing what you can come up with that will work for a majority of test cases.
– Malachi
May 15 '14 at 21:36
• How are you going to deal with a surname of "van den Platz"? "de Wolfe"? "vanCamp"? May 15 '14 at 22:32
• Yes, there are a lot of situations to account for. I can only hope I code for most of them! May 15 '14 at 23:24

If you are going to create a list of the last names it will get very big, but you would have a list of the names so you could instead

surnames.Add("McDonald")


And then

else
foreach name in surnames
if lcase(item) = lcase(name) then
xWord = name
end if
next
end if


But, this would get rather long as you add the names in, which is a big downfall when talking about maintenance especially on a VBScript.

• This is definitely something to build on. How come when I try something like O'Neil, it won't keep the capitalization on the N? May 15 '14 at 23:11
• if you have it stored in your ArrayList like O'Neil it will work, but if you have it stored O'neil than that is what will be returned
– Malachi
May 15 '14 at 23:33