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 / [EMAIL PROTECTED] [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: 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? 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 [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: Replacing special characters in a string
Richard, Replace(inputstring,chr(13)chr(10),'','ALL') Should do it HTH _ From: Richard Crawford [mailto:[EMAIL PROTECTED] 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 / [EMAIL PROTECTED] _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: Replacing special characters in a string
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 _ From: Richard Crawford [mailto:[EMAIL PROTECTED] 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 / [EMAIL PROTECTED] _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]
RE: Replacing special characters in a string
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 From: Richard Crawford [mailto:[EMAIL PROTECTED] 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 / [EMAIL PROTECTED] [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]