Solved

text formating

Posted on 2003-11-19
10
164 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 

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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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