|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Replacing special characters in a string
I have a set of strings that contain carriage returns. I'd like to goRichard Crawford 06/07/04 05:28 P Richard,Kev McCabe 06/07/04 05:39 P The CR is ascii 13. I use Replace(myvar, Chr(13), "", "ALL"). You may alsopTyler Clendenin 06/07/04 05:41 P > I have a set of strings that contain carriage returns. I'dDave Watts 06/07/04 05:34 P Richard,Dave Phillips 06/07/04 05:57 P 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 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 _____ 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 _____ ----- 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 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 ________________________________
|
February 08, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||