Mimic PHP’s uc_words() function with ASP

by admin on July 24, 2009 · 0 comments

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

Previous post:

Next post: