- see footer for list info -<
I've done a very simple implementation of this before - I use CSS. UCASE
the variable then text-transform: capitalize.
On 22/11/06, RichL <[EMAIL PROTECTED]> wrote:
>- see footer for list info -<
Thanks for the input guys... regex is a good candidate... my regex is
pretty rusty
The CapFirstTitle() code looks interesting and also has a list of
words to not capitalise:
<cfscript>
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;
}
</cfscript>
I'll have a play with this and also the regexes
Thanks very much guys
On 11/22/06, Peter Boughton <[EMAIL PROTECTED]> wrote:
> >- see footer for list info -<
> Ah, I nearly had it. Ish. Didn't think the \U and \L stuff worked with
> CF, but it apparently does. That's good to know. :)
>
> A slight modification though:
> test2 = reReplace(test, "(\b\w)(\w*)\b", "\u\1\L\2","ALL");
>
> ( \u[char] is equivalent to \U[char]\E )
>
>
> On 11/22/06, Simon Baynes <[EMAIL PROTECTED]> wrote:
> > >- see footer for list info -<
> > Use RegEx, looping trhough a list of words is ludicrous:-
> >
> >
> > <cfscript>
> > test = "VIRGIN ISLANDS";
> >
> > test2 = reReplace(test, "(\b\w)(\w*)\b", "\U\1\E\L\2","ALL");
> > </cfscript>
> > <cfoutput>#test2#</cfoutput>
> >
> >
> >
> > On 11/22/06, RichL <[EMAIL PROTECTED]> wrote:
> > > >- see footer for list info -<
> > > I have just found CapFirstTitle on CFLib which looks interesting
> > >
> > > On 11/22/06, Damien Gallagher <[EMAIL PROTECTED]> wrote:
> > > > >- see footer for list info -<
> > > > I think there's a UDF to do just this on Ray Camden's site...
> > > >
> > > > RichL wrote:
> > > > >> - see footer for list info -<
> > > > > Hi Guys
> > > > >
> > > > > I have a country reference table where all of the country names
are
> > > > > held in upper case.
> > > > >
> > > > > I want to be able to output in lower case but keep the caps
where
> > > > > appropriate (e.g. UNITED KINGDOM to United Kingdom).
> > > > >
> > > > > However I think that this going to be close to impossible as
there are
> > > > > values such as:
> > > > >
> > > > > VIRGIN ISLANDS (BRITISH)
> > > > > VIRGIN ISLANDS (U.S.)
> > > > > WALLIS AND FUTANA
> > > > >
> > > > > So using a function to capitalise the first letter of each word
won't
> > > > > really work.
> > > > >
> > > > > How have people approached this situation and has anybody found
any
> > > > > good solution?
> > > > >
> > > > > Also, is there a UDF around for capitalising the first letter of
each
> > > > > word?
> > > > >
> > > > > Thanks in advance
> > > > >
> > > > _______________________________________________
> > > >
> > > > For details on ALL mailing lists and for joining or leaving lists,
go to http://list.cfdeveloper.co.uk/mailman/listinfo
> > > >
> > > > --
> > > > CFDeveloper Sponsors:-
> > > > >- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
> > > > >- Lists hosted by www.Gradwell.com -<
> > > > >- CFdeveloper is run by Russ Michaels, feel free to volunteer
your help -<
> > > >
> > >
> > >
> > > --
> > > Rich
> > > _______________________________________________
> > >
> > > For details on ALL mailing lists and for joining or leaving lists,
go to http://list.cfdeveloper.co.uk/mailman/listinfo
> > >
> > > --
> > > CFDeveloper Sponsors:-
> > > >- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
> > > >- Lists hosted by www.Gradwell.com -<
> > > >- CFdeveloper is run by Russ Michaels, feel free to volunteer your
help -<
> > >
> >
> >
> > --
> > Simon Baynes
> > www.simonbaynes.com
> > _______________________________________________
> >
> > For details on ALL mailing lists and for joining or leaving lists, go
to http://list.cfdeveloper.co.uk/mailman/listinfo
> >
> > --
> > CFDeveloper Sponsors:-
> > >- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
> > >- Lists hosted by www.Gradwell.com -<
> > >- CFdeveloper is run by Russ Michaels, feel free to volunteer your
help -<
> >
>
>
> --
> \ \
> Peter Boughton
> blog.bpsite.net
> / /
> _______________________________________________
>
> For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
>
> --
> CFDeveloper Sponsors:-
> >- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
> >- Lists hosted by www.Gradwell.com -<
> >- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
-<
>
--
Rich
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
>- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
-<
--
Nick Tong
web: http://talkwebsolutions.co.uk
blog: http://succor.co.uk
f..works: http://cfframeworks.com
short urls: http://wapurl.co.uk
green link: http://wapurl.co.uk/?4Z2YDLX
_______________________________________________
For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo
--
CFDeveloper Sponsors:-
- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
- Lists hosted by www.Gradwell.com -<
- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<