Solved

text formating

Posted on 2003-11-19
10
159 Views
Last Modified: 2013-12-24
I am trying to find out the best way that once a person fills out a form that I may alter the case of the text inserted.

ex
if the person enters a name "bob" I would like to insert that into the db like "Bob.
and they insert a a long line of text "my company name is name"  then I would like to insert it as "My Company Name Is Name".

Any suggestions.
0
Comment
Question by:jriver12
  • 5
  • 4
10 Comments
 
LVL 10

Expert Comment

by:Mause
Comment Utility
Hi there,

So you want every first letter of a word in uppercase?
you can do this:

<CFSET text = "my company name is name">
<CFSET text_new = "">

<cfloop index="word" list="#text#" delimiters=" ">
      <CFSET text_new = text_new&' '&ucase(left(word,1))&right(word,len(word)-1)>
</cfloop>
<cfoutput>#text_new#</cfoutput>

Or even better try to find a rereplace function
(sorry no time to find out right now, maybe later)

hope this helps

Mause
0
 

Author Comment

by:jriver12
Comment Utility
Mause,
your comment works if all letters are in lcase, but as we all know the user will sometimes put all in ucase, I would like to convert all strings to ucase(1) and the rest lower.
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
that it will be like this:
<CFSET text_new = text_new&' '&ucase(left(word,1))&lcase(right(word,len(word)-1))>
0
 

Author Comment

by:jriver12
Comment Utility
MAuse,
I am encountering an error when the string contains "&,-". EX a & B co?
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
what is the error?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:jriver12
Comment Utility
Error Diagnostic Information

An error occurred while evaluating the expression:


 company_new = company_new&' '&ucase(left(word,1))&lcase(right(word,len(word)-1))



Error near line 40, column 7.
--------------------------------------------------------------------------------

Parameter 2 of function Right which is now "0" must be a positive integer

COMPANYNAME=test & test
0
 
LVL 10

Accepted Solution

by:
Mause earned 500 total points
Comment Utility
I see try this:

<cfloop index="word" list="#text#" delimiters=" ">
      <CFSET text_new = text_new&' #ucase(left(word,1))#'>
      <CFIF len(word) GT 1 >
      <CFSET text_new = text_new&lcase(right(word,len(word)-1))>
      </cfif>
</cfloop>

Also only when the first char of a word is a-z it will be A-Z
and there is a [SPACE] as first char of the new string so use TRIM when dispaly or insert/update db

Mause
0
 

Author Comment

by:jriver12
Comment Utility
that worked great.
thank you much Sire!
0
 
LVL 10

Expert Comment

by:Mause
Comment Utility
NP
0
 
LVL 17

Expert Comment

by:anandkp
Comment Utility
I guess a better way wld have been to use functions available in backend - like INITCAP in Oracle :)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now