• home
  • forum
  • my
  • kt
  • download
  • Title Case Function In Asp

    Author: 2008-08-04 08:54:52 From:

    Ever wonder why there are built in functions to make stuff lower case and upper case, but not one to put something into proper case? Well we did! It's built into Visual Basic using the StrConv(string, vbProperCase) command so why can't we use it in VBScript? Well now you can.

    I have made a simple function that will convert text to proper case, here is the code:

    Function TitleCase(Txt)
    If txt <> "" Then
    Txt=LCase(CStr(Txt))
    x=Instr(1,Txt,chr(32),vbTextCompare)
    If x = 0 Then
    TitleCase=UCase(Left(Txt,1)) & Mid(Txt,2,len(Txt)-1)
    ElseIf x > 0 Then
    tmp = Split(Txt,chr(32))
    For I = LBound(tmp) To Ubound(tmp)
    newStr = newStr & (UCase(Left(tmp(i),1)) & Mid(tmp(i),2,len(tmp(i))-1)) & " "
    Next
    newStr=Left(newStr,Len(newStr)-1)
    TitleCase=newStr
    End If
    Set tmp = Nothing
    End If
    End Function

    discuss this topic to forum

    relation tutorial

    No relevant information

    New

    Hot