House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Replacing special characters in a string

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Richard,
Kev McCabe
06/07/04 05:39 P
Richard,
Dave Phillips
06/07/04 05:57 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Richard Crawford
06/07/2004 05:28 PM

I have a set of strings that contain carriage returns.  I'd like to go through and strip them out.  I figure the REPLACE function would do the job but I'm not sure how to refer to the carriage returns. INPUT STRING: "I am a string with a carriage return" OUTPUT STRING: "I am a string with a carriage return" Any hints out there? -- Richard S. Crawford Programmer III, UC Davis Extension Distance Learning Group (http://unexdlc.ucdavis.edu) (916)327-7793 / rcrawford@unexmail.ucdavis.edu

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Kev McCabe
06/07/2004 05:39 PM

Richard, Replace(inputstring,chr(13)chr(10),'','ALL') Should do it HTH   _____ Sent: 07 June 2004 22:24 To: CF-Talk Subject: Replacing special characters in a string I have a set of strings that contain carriage returns.  I'd like to go through and strip them out.  I figure the REPLACE function would do the job but I'm not sure how to refer to the carriage returns. INPUT STRING: "I am a string with a carriage return" OUTPUT STRING: "I am a string with a carriage return" Any hints out there? -- Richard S. Crawford Programmer III, UC Davis Extension Distance Learning Group (http://unexdlc.ucdavis.edu) (916)327-7793 / rcrawford@unexmail.ucdavis.edu   _____  

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tyler Clendenin
06/07/2004 05:41 PM

The CR is ascii 13.  I use Replace(myvar, Chr(13), "", "ALL"). You may alsop need to worry about line feeds which is character 10. Tyler Clendenin GSL Solutions   _____ Sent: Monday, June 07, 2004 5:24 PM To: CF-Talk Subject: Replacing special characters in a string I have a set of strings that contain carriage returns.  I'd like to go through and strip them out.  I figure the REPLACE function would do the job but I'm not sure how to refer to the carriage returns. INPUT STRING: "I am a string with a carriage return" OUTPUT STRING: "I am a string with a carriage return" Any hints out there? -- Richard S. Crawford Programmer III, UC Davis Extension Distance Learning Group (http://unexdlc.ucdavis.edu) (916)327-7793 / rcrawford@unexmail.ucdavis.edu   _____  

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
06/07/2004 05:34 PM

----- Excess quoted text cut - see Original Post for more ----- You can use the regular Replace, ReplaceList, or ReplaceNoCase functions. Carriage returns consist of ASCII characters 13 and/or 10, depending on the operating system on which the original content was created. You can reference ASCII characters using the Chr() function: <cfset output = Replace(input, Chr(13), "", "ALL")> <cfset output = Replace(output, Chr(10), "", "ALL")> Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ phone: 202-797-5496 fax: 202-797-5444

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Phillips
06/07/2004 05:57 PM

Richard, Here's what I do: In my application.cfm file, I have a globally scoped variable called CRLF like this: <CFSET CRLF = chr(13) & chr(10) > Then, in all my templates, whenever I need to take out a carriage return, I just do the following (this example is changing it to HTML line breaks): <cfoutput> #replacenocase(string,CRLF,"<br>","All")# </cfoutput> I use replacenocase as it seems to me their might be a tiny performance benefit since it's not even concerned about case (even though that wouldn't matter for special characters anyway. I believe you can also do: replacenocase(string,chr(13)&chr(10),"all") That should work too. Hope this helps. Dave ________________________________ Sent: Monday, June 07, 2004 4:24 PM To: CF-Talk Subject: Replacing special characters in a string I have a set of strings that contain carriage returns.  I'd like to go through and strip them out.  I figure the REPLACE function would do the job but I'm not sure how to refer to the carriage returns. INPUT STRING: "I am a string with a carriage return" OUTPUT STRING: "I am a string with a carriage return" Any hints out there? -- Richard S. Crawford Programmer III, UC Davis Extension Distance Learning Group (http://unexdlc.ucdavis.edu) (916)327-7793 / rcrawford@unexmail.ucdavis.edu ________________________________


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 08, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29