Solved

text formating

Posted on 2003-11-19
10
160 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
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
 

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
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
file too large for website 6 67
cloud web Service looking for a home... 3 100
UPLOAD FILE TO Web API USING POST 5 109
spamming  on Hosted svrs? 6 75
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

20 Experts available now in Live!

Get 1:1 Help Now