Library code snippets

Proper Capitalization

Proper Capitalization

This code is used to capitalize the first letter of every word in a string passed as an argument.  All you have to do is past the function code near the beginning of your script command and call the function using the command PropCase(String).  Simple as that.

<%
Function PropCase(strTemp)
 Dim intFound
 Dim strTempName

 Do
   strTempName = strTempName & UCase(Left(strTemp, 1))
   strTemp     = Right(strTemp, Len(strTemp) - 1)
   intFound    = InStr(strtemp, " ")
   If intFound <> 0 Then
     strTempName = strTempName & Left(strTemp, intFound)
     strTemp = Right(strTemp, Len(strTemp) - intFound)
   Else
     strTempName = strTempName & strTemp
     Exit Do
   End If
 Loop While intFound <> 0
 Response.Write strTempName
End Function
%>
AddThis

Comments

  1. 16 Sep 2005 at 07:03

    I am fairly new to ASP and so forth,,  alot of learning....  been give the code to capitalize words of:


    <%
    Function PropCase(strTemp)
    Dim intFound
    Dim strTempName


    Do
     strTempName = strTempName & UCase(Left(strTemp, 1))
     strTemp     = Right(strTemp, Len(strTemp) - 1)
     intFound    = InStr(strtemp, " ")
     If intFound <> 0 Then
       strTempName = strTempName & Left(strTemp, intFound)
       strTemp = Right(strTemp, Len(strTemp) - intFound)
     Else
       strTempName = strTempName & strTemp
       Exit Do
     End If
    Loop While intFound <> 0
    Response.Write strTempName
    End Function
    %>


    When my users log on it says: welcome with the script <%
    response.write(Session("MM_Username"))
    %>!  I am trying to fit this code to capitalize with the code I already have and I am not sure how or where to place it.  


    I appreciate anybodys help that can offer it.  Thanks, Chuck
    < Prev | 1 | Next >


     

  2. 16 Sep 2005 at 07:01

    I am fairly new to ASP and so forth,,  alot of learning....  been give the code to capitalize words of:


    <%
    Function PropCase(strTemp)
    Dim intFound
    Dim strTempName


    Do
      strTempName = strTempName & UCase(Left(strTemp, 1))
      strTemp     = Right(strTemp, Len(strTemp) - 1)
      intFound    = InStr(strtemp, " ")
      If intFound <> 0 Then
        strTempName = strTempName & Left(strTemp, intFound)
        strTemp = Right(strTemp, Len(strTemp) - intFound)
      Else
        strTempName = strTempName & strTemp
        Exit Do
      End If
    Loop While intFound <> 0
    Response.Write strTempName
    End Function
    %>


    When my users log on it says: welcome with the script <%
    response.write(Session("MM_Username"))
    %>!  I am trying to fit this code to capitalize with the code I already have and I am not sure how or where to place it.  


    I appreciate anybodys help that can offer it.  Thanks, Chuck

  3. 02 Feb 2005 at 00:25

    Hi Ken,


    I found your function to proper case a string very useful. Would it be possible for the function to work if there were linefeeds in the string?


    E.G


    mr anyone
    15 anywhere street
    london


    This address string format confused the function a bit because of the linefeeds.


    How could the function be changed to deal with this type of string.


    Thank you.


    Colin

  4. 29 Dec 2004 at 09:19

    An alternative to do a similar thing but which possibly runs a lot faster:
    <%
    Function EIPropCase(EIString)
       ' Developed by Ken Good of Edge Impact Consulting Ltd, www.edgeimpact.co.uk
       ' This function will change the first letter of every word in a sting to upper case, for
       ' example the string "the west   wing is    where we practice karate" will be changed to
       ' "The West Wing Is Where We Practice Karate"
       Dim EIResultArray
       Dim EICnt
       EIResultArray = split(EIString," ")
       For EICnt = lbound(EIResultArray) to ubound(EIResultArray)
           EIPropCase = EIPropCase & " " & ucase(Left(EIResultArray(EICnt),1)) & mid(EIResultArray(EICnt),2)
       Next
       EIPropCase = mid(EIPropCase,2)
    End Function
    %>

  5. 04 Feb 2004 at 10:40

    This did exactly what I needed it to do. I had a list of company names that were all in caps, so I used this little function. Instead of "Response.Write strTempName" I used "PropCase = strTempName".


    Thanks for the code.

Leave a comment

Sign in or Join us (it's free).

Related discussion

Related jobs