IBM developerWorks
           ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 5th, 2004, 04:55 PM
FrozenShade FrozenShade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 10 FrozenShade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Capitalisation after first letter

I've been using CapFirstTitle from cflib for some time now and it works great. On this occasion however I need to make a modification and have it also capitalising the first letter after an open bracket, which currently it does not do...Here's the script
--------------------
function capFirstTitle(initText){

var Words = "";
var j = 1; var m = 1;
var doCap = "";
var thisWord = "";
var excludeWords = ArrayNew(1);
var outputString = "";

initText = LCASE(initText);

//Words to never capitalize
excludeWords[1] = "an";
excludeWords[2] = "the";
excludeWords[3] = "at";
excludeWords[4] = "by";
excludeWords[5] = "for";
excludeWords[6] = "of";
excludeWords[7] = "in";
excludeWords[8] = "up";
excludeWords[9] = "on";
excludeWords[10] = "to";
excludeWords[11] = "and";
excludeWords[12] = "as";
excludeWords[13] = "but";
excludeWords[14] = "if";
excludeWords[15] = "or";
excludeWords[16] = "nor";
excludeWords[17] = "a";

//Make each word in text an array variable

Words = ListToArray(initText, " ");

//Check words against exclude list
for(j=1; j LTE (ArrayLen(Words)); j = j+1){
doCap = true;

//Word must be less that four characters to be in the list of excluded words
if(LEN(Words[j]) LT 4 ){
if(ListFind(ArrayToList(excludeWords,","),Words[j])){
doCap = false;
}
}

//Capitalize hyphenated words
if(ListLen(Words[j],"-") GT 1){
for(m=2; m LTE ListLen(Words[j], "-"); m=m+1){
thisWord = ListGetAt(Words[j], m, "-");
thisWord = UCase(Mid(thisWord,1, 1)) & Mid(thisWord,2, LEN(thisWord)-1);
Words[j] = ListSetAt(Words[j], m, thisWord, "-");
}
}

//Automatically capitalize first and last words
if(j eq 1 or j eq ArrayLen(Words)){
doCap = true;
}

//Capitalize qualifying words
if(doCap){
Words[j] = UCase(Mid(Words[j],1, 1)) & Mid(Words[j],2, LEN(Words[j])-1);
}
}

outputString = ArrayToList(Words, " ");

return outputString;

}
------------------

It will even capitalise the first letter of hyphenated words. Is there any way to add something to get it to cap the first letter AFTER an open bracket, as currently it makes these all lowercase?

TIA
MarkH

Reply With Quote
  #2  
Old October 5th, 2004, 05:27 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
I'm sure it could be done, but I don't have the time to write it myself. It sounds like a good exercise to hone your skills to me!
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old October 10th, 2004, 08:52 PM
FrozenShade FrozenShade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 10 FrozenShade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I just run this last, after the rest of the script and it works on MX, but not on version 5...

function headingCaps(str) {
var result = "";
result = reReplace(str, "\b(\w)", "\U\1", "all");
result = reReplace(result, "\b(The|A|An)\b", "\L\1", "all");
result = reReplace(result, "(^|\()(\w)", "\1\U\2", "all");
return result;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Capitalisation after first letter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway