Sort of irrelevant, but I’ll mention it anyway in case someone else finds it useful.
A while back, I had the task of converting a customer name and address database from ALL CAPS to Sensible Smart Case; there’s a VB native function called VBProperCase, but it wasn’t flexible enough; we needed something that:
-Used Proper Case on most words
-Rendered certain known abbreviations in full upper case
-Wrote surnames such as McTavish and O’Flaherty this way
-Rendered postal codes (any substring containing a number) fully in upper case.
-left small words such as ‘of’, ‘in’ etc completely in lower case.
So I wrote a custom VB function to handle it; here it is (it’s a bit rough and ready, but it works surprisingly well):
Public Function SmartCase(ConvertStr As String) As String
Dim mPointer As Integer
Dim mletter As Integer
Dim mtemploop As Integer
Dim mWord As String
Dim mchar As String
If ConvertStr = "" Then
SmartCase = " "
Exit Function
End If
mPointer = 0
'loop through entire string
Do
mWord = ""
'loop to get the next word
Do
mPointer = mPointer + 1
mWord = mWord + Mid(ConvertStr, mPointer, 1)
Loop Until InStr(" /-,.(){}[]+&@", Mid(ConvertStr, mPointer, 1)) > 0 Or (mPointer > Len(ConvertStr))
'process the word:
'Default word conversion:
mletter = 0
Do
mletter = mletter + 1
If InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(mWord, mletter, 1)) > 0 Then
mWord = (Mid(mWord, 1, mletter - 1)) & UCase(Mid(mWord, mletter, 1)) & LCase(Mid(mWord, mletter + 1, Len(mWord) - 1))
mletter = Len(mWord) + 1
End If
Loop Until mletter > Len(mWord)
'Conditional conversions:
'Celts Mc~ and O'~
If (Mid(mWord, 1, 2) = "Mc") Or (Mid(mWord, 2, 1) = "'") Then
mWord = UCase(Mid(mWord, 1, 1)) & LCase(Mid(mWord, 2, 1)) & UCase(Mid(mWord, 3, 1)) & LCase(Mid(mWord, 4, Len(mWord) - 2))
'(capitalise first and third letter, but not the rest)
End If
'Small words - do not capitalise at all unless it is the first word in the string
If (InStr("-A-An-And-At-In-Is-Or-The-Of-", "-" & Trim(mWord) & "-") > 0) And ((mPointer - Len(mWord)) > 0) Then
'(hyphens for Jack-in-the-Box and also as delimiters - NB: you can customise this list)
mWord = LCase(mWord)
End If
'Common abbreviations - capitalise entirely
If InStr("-Pb-Hb-Whs-", "-" & Trim(mWord) & "-") > 0 Then
'(hyphens as above NB: my abbreviations are for Paperback, Hardback and Warehouse, but you can customise them)
mWord = UCase(mWord)
End If
'Words containing a numeric character - capitalise entirely
For mtemploop = 0 To 9
If InStr(mWord, Trim(Str(mtemploop))) > 0 Then
mWord = UCase(mWord)
End If
Next
SmartCase = SmartCase & mWord
Loop Until mPointer > Len(ConvertStr)
End Function