ucwords() in Classic ASP / Proper Case or Title Case in ASP!!

This tutorial shows how you can make first letter capital (upper case) of each word in Classic ASP.
There is no predefined function like PHP ucwords() in Classic ASP. So, here is the function you can use it to do the same ucwords() in classic ASP

Only function (double click on the code to copy it):

<%
function ucwords(strInput)

    Dim iPosition,iSpace,strOutput  

    iPosition = 1

    do while InStr(iPosition, strInput, " ", 1) <> 0
        iSpace = InStr(iPosition, strInput, " ", 1)
        strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
        strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))
        iPosition = iSpace + 1
    loop

    strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
    strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))

    ucwords = strOutput
end function
%>

Function with Usage Example for your convenience:

<%
function ucwords(strInput)

    Dim iPosition,iSpace,strOutput  

    iPosition = 1

    do while InStr(iPosition, strInput, " ", 1) <> 0
        iSpace = InStr(iPosition, strInput, " ", 1)
        strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
        strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))
        iPosition = iSpace + 1
    loop

    strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
    strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))

    ucwords = strOutput
end function

'usage example
response.write(ucwords("spider man")&"<br>")

dim afterCase

afterCase = ucwords("this is just a test")

response.write(afterCase)

%>

Leave a Reply

Theme: Overlay by Kaira
Agurchand