Solved

text formating

Posted on 2003-11-19
10
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 10

Expert Comment

by:Mause
ID: 9779127
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
ID: 9779230
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
ID: 9779274
that it will be like this:
<CFSET text_new = text_new&' '&ucase(left(word,1))&lcase(right(word,len(word)-1))>
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 

Author Comment

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

Expert Comment

by:Mause
ID: 9779810
what is the error?
0
 

Author Comment

by:jriver12
ID: 9779831
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
ID: 9779862
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
ID: 9779920
that worked great.
thank you much Sire!
0
 
LVL 10

Expert Comment

by:Mause
ID: 9780604
NP
0
 
LVL 17

Expert Comment

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

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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