patternMinor
Proper capitalization for surname like McDonald
Viewed 0 times
surnamelikemcdonaldforpropercapitalization
Problem
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
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")
conjunctions.Add("a")
conjunctions.Add("an")
conjunctions.Add("and")
conjunctions.Add("as")
conjunctions.Add("at")
' etc....
suffixes.Add("ii")
suffixes.Add("iii")
suffixes.Add("iv")
suffixes.Add("vi")
suffixes.Add("vii")
suffixes.Add("viii")
suffixes.Add("ix")
surnames.Add("mcdonald")
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
queryForHeading = xCompleteWord
queryForHeading = Mid(queryForHeading, 2)
queryForHeading = UCase(Mid(queryForHeading, 1, 1)) & Mid(queryForHeading, 2)Solution
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
And then
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.
surnames.Add("McDonald")And then
else
foreach name in surnames
if lcase(item) = lcase(name) then
xWord = name
end if
next
end ifBut, this would get rather long as you add the names in, which is a big downfall when talking about maintenance especially on a VBScript.
Code Snippets
surnames.Add("McDonald")else
foreach name in surnames
if lcase(item) = lcase(name) then
xWord = name
end if
next
end ifContext
StackExchange Code Review Q#49884, answer score: 3
Revisions (0)
No revisions yet.