PDA

View Full Version : How do you capitalize the first letter of a string?


Gladstone
09-13-2002, 12:14 AM
How do you capitalize the first letter of a string? I'm fiddling around with an application I'm developing (vbscript in asp) which presents the need to do this and I'm a bit stumped. Don't see the answer in any of my books I have kicking around here. Didn't see the answer browsing around on the net. Seems like a simple thing to want to do. Probably is and I'm just sporting a case of the stupids. Anyone want to save me from further embarrassment?

Gladstone

glenngv
09-13-2002, 04:16 AM
str = "glenn"
str = ucase(mid(str,1,1)) & mid(str,2)
response.write str

Gladstone
09-13-2002, 05:32 PM
Thanks Glenn. Last night I came up with this one:

str = "gladstone"
str = ucase(left(str, 1)) + right(str, len(str)-1)
Response.Write str

Do you think either would be more efficient? I have to process alot of them at a time and a little gain will go a long way for me.

Gladstone

whammy
09-14-2002, 07:17 AM
As far as I can tell, that kind of performance difference (if there is one) is negligible.

I'd do this though...

str = "gladstone"
If str <> "" Then
str = ucase(left(str, 1)) + right(str, len(str)-1)
End If
Response.Write str


Because you will get errors if the string doesn't exist otherwise.

Mhtml
09-15-2002, 10:32 AM
lol...depending on how much time you have you could do it in any number of ways...

whammy
09-15-2002, 11:21 PM
Yeah... there are many many ways to do it. :D