Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

making the first letter of every word a capital

Participant ,
May 13, 2006 May 13, 2006
hello CF oracles

could you guys please advise me the best way to make the first letter in every word of a string a capital letter. (and make all the other letters lower case).

eg. convert "the quick brown fox" into "The Quick Brown Fox"
or convert "THE QUICK BROWN FOX" into "The Quick Brown Fox"

I am taking form data and inserting it into my table, so i want to get it right as the data is inserted.

i found a "UDF" on CFLIb.org that proports to do this, but i don't know how to set up a UDF, are there other ways or is this considered the best approach. http://www.cflib.org/udf.cfm?id=9&enable=1

thanks for any help you can give me
TOPICS
Getting started
4.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2006 May 13, 2006
Treat your string as a space delimted list. Loop through it.

Use left and ucase for the first letter.
Use right, len, and lcase for the rest.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 13, 2006 May 13, 2006
hi Dan - alas you use several terms in there which are new on me. I've managed to get to this;

#Left( UCase( "#mystring#" ), 1 )##Right( LCase( "#mystring#" ), Len("#mystring#" ) - 1 )#

but that only does the first letter of the first word of mystring. i fear this "looping" is beyong me

don't worry if you haven't got one to hand (or feel i'm asking too much), but if you've got a snippet including your looping suggestion i'd be very grateful indeed..

hope you don't mind me asking
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2006 May 13, 2006
A list is a string where each element is separated by a single character called a delimiter. The most common delimiter is a comma. Here is a list.
1,2,3,4,5

Any sentence can be treated as a list, The delimiter is a space.

To learn about cold fusion list functions, google the words coldfusion list functions. The two functions you need are called ListGetAt and ListLen.

To learn about loops, google <cfloop>. One of the things you can do with this tag is loop through a list.

By the way, well done on figuring out how to do a single word.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 14, 2006 May 14, 2006
hi Dan thanks very much. I have made an executive decision to do a bit of a hack for now as my site is only small so if a user enters something in the wrong way i can quickly manually update it myself.

so now i have this which works 9 times out of ten if the user enters a one word name eg "bill" or "fred" of "jane" then it works just fine

the only time it doesnt work is if the user's name is more than 1 word (or is hyphenated) eg "mary anne" or "anne-marie" hence the first cfif line - in these cases i can manually update

i put this here in case it is of use to anyone else

cheers
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 14, 2006 May 14, 2006
there is a custom tag out there that does Camelcase which is what you are
trying to do, where every word entered starts with a capital. I'll have to
look for it in my archives as I forget its name.

I'll get back to you on this...


"happysailingdude" <webforumsuser@macromedia.com> wrote in message
news:e46tjv$e30$1@forums.macromedia.com...
> hi Dan thanks very much. I have made an executive decision to do a bit of
> a
> hack for now as my site is only small so if a user enters something in the
> wrong way i can quickly manually update it myself.
>
> so now i have this which works 9 times out of ten if the user enters a one
> word name eg "bill" or "fred" of "jane" then it works just fine
>
> the only time it doesnt work is if the user's name is more than 1 word (or
> is
> hyphenated) eg "mary anne" or "anne-marie" hence the first cfif line - in
> these
> cases i can manually update
>
> i put this here in case it is of use to anyone else
>
> cheers
>
> <cfif not (FORM.firstName contains " " or FORM.firstname contains "-")>
> '#Left( UCase( "#FORM.firstName#" ), 1 )##Right( LCase(
> "#FORM.firstName#" ), Len("#FORM.firstName#" ) - 1 )#'
> <cfelse>
> '#FORM.firstName#'
> </cfif>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 14, 2006 May 14, 2006
found it, here's the top info, Titlecase is what you want for this.:

changecase.cfm
Rev 1.01
cf_changecase is a simple custom tag to format case in given string.
(c) 2001, Rizal Firmansyah, rizal.firmansyah@kindara.com

Input var:
* case (mandatory)
possible inputs are
- sentencecase: Sentence case (default)
- titlecase: Title Case
- lowercase: lowercase
- uppercase: UPPER CASE



"happysailingdude" <webforumsuser@macromedia.com> wrote in message
news:e46tjv$e30$1@forums.macromedia.com...
> hi Dan thanks very much. I have made an executive decision to do a bit of
> a
> hack for now as my site is only small so if a user enters something in the
> wrong way i can quickly manually update it myself.
>
> so now i have this which works 9 times out of ten if the user enters a one
> word name eg "bill" or "fred" of "jane" then it works just fine
>
> the only time it doesnt work is if the user's name is more than 1 word (or
> is
> hyphenated) eg "mary anne" or "anne-marie" hence the first cfif line - in
> these
> cases i can manually update
>
> i put this here in case it is of use to anyone else
>
> cheers
>
> <cfif not (FORM.firstName contains " " or FORM.firstname contains "-")>
> '#Left( UCase( "#FORM.firstName#" ), 1 )##Right( LCase(
> "#FORM.firstName#" ), Len("#FORM.firstName#" ) - 1 )#'
> <cfelse>
> '#FORM.firstName#'
> </cfif>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 15, 2006 May 15, 2006
LATEST
Format the data in the form, as the user types, BEFORE it gets to the server using css. It's not foolproof, ex. O'Brien renders as O'brien.

But it will pre-format the data so your backend processing won't have to work so hard The css may be enough for your needs.

You can use a class or inline style:

<style type="text/css">
.cap {
text-transform: capitalize;
}
</style>

<form>
<input type="text" name="x1" style="text-transform:capitalize;">
<input type="text" name="x2" class="cap">
</form>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources