Title Case Proper Names

Here's a quick VBScript example of how to turn a lower case name into a properly cased name.

Here's a quick VBScript example of how to turn a lower case name into a properly cased name. Just copy and paste this example into a .vbs file and double click it. Of course, this will work in ASP without the msgbox functions.


Function CapitalizeValue(sFullName)

Dim fCapitalizeNextLetter
Dim sNewName
Dim sChar

sFullName = Trim(sFullName)

if sFullName = "" then CapitalizeValue = sFullName

fCapitalizeNextLetter = true

For i=1 to Len(sFullName)

sChar = Mid(sFullName,i,1)

if (fCapitalizeNextLetter = true) then
if IsLetter(sChar) = true then
sChar = UCase(sChar)
fCapitalizeNextLetter = false
else
fCapitalizeNextLetter = true
end if
else
if IsLetter(sChar) = false then
fCapitalizeNextLetter = true
end if
end if


sNewName = sNewName & sChar

Next

CapitalizeValue = sNewName

end Function

function IsLetter(sChar)

fRet = false
nASCII = ASC(sChar)

if ((nASCII >=65) and (nASCII <=90)) then fRet = true ' Upper case letters
if ((nASCII >=97) and (nASCII <=122)) then fRet = true ' Lower case letters

IsLetter = fRet

end function

msgbox CapitalizeValue("robbe d. morris")
msgbox CapitalizeValue("robbe o'brien")
msgbox CapitalizeValue("robbe van stud")


Submission Date:  9/23/2005 2:54:31 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (348 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP