x
Solved

classic asp Capital Case

Posted on 2011-09-20
Medium Priority
585 Views
I have a data like los angeles and I would like to convert to Los Angeles

How can I do that in classic asp? I just need first letter is capital.
and the data came from sql server database.
0
Question by:Webboy2008

LVL 16

Expert Comment

ID: 36570860
0

LVL 61

Expert Comment

ID: 36570910
use a function like the one here:

http://www.4guysfromrolla.com/webtech/092798-1.shtml
0

LVL 29

Expert Comment

ID: 36571205
You can use this:

Function PCase(word)
PCase = UCase(Left(word,1)) & LCase(Mid(word,2))
End Function

Then all you need to do is:

PCase(state) or whatever your form fieldname is.
0

LVL 11

Accepted Solution

G_H earned 2000 total points
ID: 36572654
Hi There,

I have two functions I use to do this...

They will work for you, but also work for people's names, such as "McDonald"...

Use as:

Str = "loS anGeles"
SortedText = ProperCase(Str)

``````'' ## Proper Case (Name Case) a sentance, or name
'' ## Uses PCaseWord to do the donkey work
Public Function ProperCase(Input)
Dim strOut, astr, i, j, t

strOut = LCase(Input)
astr = Split(strOut, " ")

for i = 0 to UBound(astr)
if InStr(astr(i), "-") = 0 then
astr(i) = PCaseWord(astr(i))
else
t = Split(astr(i), "-")
for j = 0 to UBound(t)
t(j) = PCaseWord(t(j))
next
astr(i) = Join(t, "-")
end if
next

ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
Function PCaseWord(strIn)
Dim strOut, t

t = Mid(strIn, 1, 3)
if t = "mac" then
strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
else
t = Mid(t, 1, 2)
if t = "mc" then
strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
elseif t = "o'" then
strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
else
strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
end if
end if

PCaseWord = strOut
End Function
``````

@sammy: I think your code will result in "Los angeles" rather than "Los Angeles"...?

GH
0

LVL 29

Expert Comment

ID: 36573502
Oops, you are right but it is a trivial fix:

``````Function PCase(word)
PCase = UCase(Left(word,1)) & UCase(Mid(word,2))
End Function
``````
0

Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.