Title Case Function In Asp

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


Tags:

Subscribe to PlanetMaks

PlanetMaks updated regularly with content related to news, tutorials, downloads and many resources. If you don't want to miss out on future posts, you can subscribe by RSS or email.

More in Asp

Related Posts

Calculate 'time ago' in asp Now a days we often see websites that show date in the form of "time ago" format e.g "2 Days 12 Hours Ago". Well, that isn't too hard to create its quite easy actually. The basic concept is to get the time difference between two dates and step by step extract different units of time from it. [...]
Function IsDate to check valid date or date variable We can check (or validate) the date variable or a date by using IsDate() function. User entered date values in a form are to be checked for correct date or not before further processing. This function takes one input and gives output as TRUE or FALSE based on the input. A valid date or date variable will return TRUE or it will return FALSE. Here [...]
Sending mail in asp Sending mail in asp through CDO is pretty simple. There are only few things to configure and you are ready to go! Here is the code for sending mail [...]
Day of Week Want to display the current day of the week in your .asp? This code will grab today’s value and utilizing select case display the day of the week. [...]
Date and Time Formats There are numerous ways to display date, time and the difference between two dates. The code below shows some of the many ways to display today and the difference between today and July 4, 1776. [...]
Display an Excel DB Excel can act as a database. It's not the fastest or the best. However, for small data bits on a server where the chance for significant simultaneous traffic is not likely excel can perform many of the basic tasks that can be accomplished in Access or [...]
Multiple Form Selection (Where In) Allowing multiple choices of data observations enables people to customize views of your data and adds value to your applications. The following example utilizes our db on the career statistics of Hammerin’ Hank Greenberg. The years he played are [...]

Most Popular in "Asp"

Create XML Documents from Access Output Active Server Pages allow for the easy ability to create dynamic views of your data on a web server, but you can also create "static" documents on the server. This can be particularly useful if you wish to distribute your information on CD or in virtually any document form. [...]
Generating a random password This function can be used to have a random password generated. It allows you to specify valid characters as well as specifying number of characters. [...]
Prevent your website from cross website attacks See how you can prevent submissions from other websites [...]
Calculate 'time ago' in asp Now a days we often see websites that show date in the form of "time ago" format e.g "2 Days 12 Hours Ago". Well, that isn't too hard to create its quite easy actually. The basic concept is to get the time difference between two dates and step by step extract different units of time from it. [...]
Multiple Form Selection Allowing multiple choices of data elements enables people to customize views of your data and adds value to your applications. The following example utilizes our db on the career statistics of Hammerin’ Hank Greenberg. The year and team he played with [...]
Function IsDate to check valid date or date variable We can check (or validate) the date variable or a date by using IsDate() function. User entered date values in a form are to be checked for correct date or not before further processing. This function takes one input and gives output as TRUE or FALSE based on the input. A valid date or date variable will return TRUE or it will return FALSE. Here [...]
Day of Week Want to display the current day of the week in your .asp? This code will grab today’s value and utilizing select case display the day of the week. [...]