ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash




Script Output:
Original String: The quick brown fox jumps over the lazy dog.
LCase (VBScript) String: the quick brown fox jumps over the lazy dog.
UCase (VBScript) String: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
PCase (ASP 101) String: The Quick Brown Fox Jumps Over The Lazy Dog.
Try it out on your input:


ASP HTML Download            FAQ

ASP.NET Version

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've run into this quite a few times and for the most part it's not a big problem. Each time I need to do it I usually use a quick hack like:

UCase(Left(strInput, 1)) & LCase(Mid(strInput, 2))

to handle it, but I've probably written it a dozen times and it gets annoying. Finally, one of our visitors got tired of doing this over and over, decided that enough is enough, and spent the time to write a function to help automate this task. Luckily for you, Brian Shamblen from Certified Capital Corporation is not only the type of person who tries to make his own coding easier, he also likes to share! I received a version of this function from Brian who was visiting the site and felt that he'd like to contribute it in the hopes that others would benefit from his work. I've "hacked and slashed" it a little and added some comments to make it seem more like an official ASP 101 sample, but the motivation and real credit goes to someone probably very much like you! You see... we actually do listen to our users once in a while! Thanks Brian!

When I recieved it, it was actually named TCase for title case. I've changed it to PCase for proper case to match it to the term that Visual Basic uses for this type of string. There are actually a few issues with the script. The main issue is: what to do with things you want to keep capitalized or those you don't? For example, I'd assume you'd want McCarthy to stay McCarthy and not change to Mccarthy. Well it doesn't. Similarly "a", "an", and "the" get changed to "A", "An", and "The" even though you wouldn't want this in a title. As far as I know, there's not easy way to handle this type of thing in a dozen line script, so we simply don't! I replicates the functionality of VB's StrConv(string, vbProperCase). If you want any more than that, I'm sorry but you'll need to look elsewhere.

Alternate Version of PCase

One of our visitors sent in an alternate version of the VBScript PCase function we published in this sample. While the original version accomplished its task using all string-based functions, his version splits the phrase into an array of words and then loops through the array capitalizing each word. It just goes to show that no matter how simple a problem is, there's almost always more than one solution.

Rather then list the code here or create a zip file, I've simply added a new function named "PCaseAlternate" to the original script. So if you're interested in the alternate version of the code just take another look at the ASP source code.


Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES