First Letter Upper Case in Classic ASP

Today I want to illustrate a quick and easy way to change all first letters of words in a string to upper case using classic ASP.

<%
Function ChagetoUpperCase(X)
Dim lcstring
Dim oldcase
Dim NewArray
Dim newString
Dim IntegerI
Dim I

lcstring = CStr(LCase(X))
oldcase = ” ”
NewArray = Split(lcstring,” “)
For IntegerI = LBound(NewArray) To UBound(NewArray)
For I = 1 To Len(NewArray(IntegerI))

If Len(NewArray(IntegerI)) = 1 Then

newString = newString & UCase(NewArray(IntegerI)) & ” ”

ElseIf I=1 Then

newString = newString & UCase(Mid(NewArray(IntegerI), I, 1))

ElseIf I = Len(NewArray(IntegerI)) Then

newString = newString & Mid(NewArray(IntegerI), I, 1) & ” ”

Else

newString = newString & Mid(NewArray(IntegerI), I, 1)

End If

Next
Next
ChagetoUpperCase = Trim(newString)
End Function
%>

Then just call the function like this:

<%
Dim MyNewText
MyNewText = “hello everyone”

Dim NewOutPut
NewOutPut = ChagetoUpperCase(MyNewText)

Response.Write NewOutPut
%>

It should output this Hello Everyone. And that’s all there is to it.

Comments are closed.