ucwords() in classic ASP or Proper Case in Classic ASP.

I understand you are working in a very Old Programming language which is not been used for years and the problem is now you have to make First letter capital for all the words in a sentence.

If you are a PHP Programmer you would have known this function called ucwords()

But, In classic ASP there is no default function like ucwords().

No worries here is the program you can just copy paste and use this in your code:

<%
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)

%>

The above function and the usage show how to Uppercase the first character of each word in a string in Classic ASP.

The output will be:
This Is Just A Test

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top