|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Replacing special characters in a string
Author: Dave Phillips
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:33036#165739
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
________________________________
Author: Tyler Clendenin
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:33036#165737
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
_____
Author: Kev McCabe
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:33036#165736
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
_____
Author: Dave Watts
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:33036#165735
----- 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
Author: Richard Crawford
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:33036#165734
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
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||