ASP Code

Mimic PHP's uc_words() function with ASP

If you are trying to convert a PHP application to ASP, it's good to have equal functionality with text formatting. This function capitalizes (converts to uppercase) the first character/letter of each word in a string, and converts the remaining characters to lowercase. This is referred to as Title casing.


'====
Function ucWords( strWords )
'====
    strWords = trim( strWords & "" )
    if len( strWords ) > 0 then
        dim arWords, i, strFormatted
        arWords = split( strWords, " " )
        for i = 0 to uBound( arWords )
            strFormatted = strFormatted & " " & ucFirst( arWords( i ) )
        next
       
        ucWords = strFormatted
    end if
End Function


'====
Function ucFirst( strWord )
'====
	strWord = trim( strWord & "" )
	if len( strWord ) > 0 then
		ucFirst = uCase( left( strWord, 1 ) ) & _
				  lcase( right( strWord, len( strWord ) - 1 ) )
	end if
End Function
Share

Leave a Reply

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

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image