Library code snippets
Proper Capitalization
By Scott Dennison, published on 14 Jul 2001
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
%>
Related articles
Related discussion
-
Tutorial
by James Crowley (5 replies)
-
Handling error database.
by James Crowley (1 replies)
-
very easy, please help: Field
by natalia (0 replies)
-
Show Stock Exchange Rate
by Shoaib Hasan (0 replies)
-
How to do the rate this resource
by CodeWarrior76 (7 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Front End Developer
in Hammersmith (£45K-£60K per annum)
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 >
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
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
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
%>
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.