|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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; } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Capitalisation after first letter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|