PDA

View Full Version : Converting a String to Proper Case


admin
06-04-2003, 03:00 PM
I had been looking for a script that would perform a "proper" function on a string, similar to the function in MS Excel. I did find a script that would work with one word strings but not multiline
strings used with address fields etc. With a little work I have written a function that will take any string and convert all words so that the first letter is uppercase, the remaining characters are lowercase.

Example to call the function:

strSql = StrSql & ChkString(Request.Form("surname")) & "', '"

Below is the function:

Function ChkString(InString)
if InString = "" then InString = " "
InString = Replace(InString, "'","''")
FoundSpace = True
OutputString = ""
for MidPosition = 1 to len(InString)
if FoundSpace = true then
OutputString = OutputString & UCase(Mid(InString,MidPosition,1))
FoundSpace = false
else
OutputString = OutputString & LCase(Mid(InString,MidPosition,1))
if Mid(InString,MidPosition,1) = " " then FoundSpace = true
if Mid(InString,MidPosition,1) = chr(10) then FoundSpace = true
end if
next
ChkString = OutputString
End Function

By Neil Beswick