Usually line breaks have the value char(10)&chr(13), so you could use
replace(string, char(10)&chr(13), "--")
But the first method is more fullproof, as it'll get any stray chr(10)'s or chr(13)'s :).
The only three characters I can think of which you will need to be escaping characters are '," and #. I mean, what else do you surround text/code with?
Jon
KH@
03-15-2002, 06:49 PM
I got an error. Any idea why?
An error occurred while evaluating the expression:
daString = "#replace(daString, char(10), "-")#"
Error near line 6, column 7.
--------------------------------------------------------------------------------
I think this is right but I still have another break chr to get rid of.
Do you know what it might be?
KH@
03-15-2002, 08:00 PM
While searching for a list of ascii charaters , their numbers and their purposes I found this ref to other OS.
[quote]Alternative Sets.
There have always been other 8-bit character sets (e.g. Mac, Unix, Windows, Web browsers, Latin-1, etc.) but it's true sucessor is going to be Unicode.[quote]
Does this mean that visitors to my pages using a Mac for instance might not have their line breaks removed/replaced?
Is their a way of using unicode in coldFusion?
Just for the heck of it, this code does what I want. I had to run the string through twice although I'm not sure why.
Just to be extra extra sure I ran it through three times then added an error catcher as well.
Bit of overkill there I guess but it seems to work.
<!--- replace list --->
<cfset daString = "#hog_script#">
<!--- 3. remove bad words and other illegal characters :
this Deleted coz of extreme bad language.
--->
<!--- 4. double check and do error relocate --->
<cfif (daString contains "'") OR (daString contains "\") OR (daString contains """") OR (daString contains"char(10)") OR (daString contains"char(13)") OR (daString contains"char(14)")>
<cflocation url="error.cfm" addtoken="No">
</cfif>
<cfset hog_script = "#daString#">
jonsteele
03-16-2002, 05:42 AM
Well I guessed you figured out your first question. Char should be chr. My fault. :)
As far as character sets go, it depends on how the data from the form field is being interpreted by the browser and sent to the server. I really have no experience with Macs.
Running it throught three times!? That should not be necessary. You may want to try using a different var name when replacing.
P.S. You can save yourself some coding by removing the "# and #" from around your functions. They're not really needed :). Kinda like entering then exiting quotes in JavaScript:
var myString = ""+stringVariable+""
Just a suggestion. Also, when you start using more complicated functions, maybe even within other functions, they tend to get in your way and will cause errors (I've been there...:rolleyes: )
KH@
03-16-2002, 09:48 AM
Yes I think you're right about 3 times but for some reason it does have to go through twice or breaks remain. I wish I knew why.
The # around functions.
I learnt from Ben Forta's books and that's the way he seems to do it. I've always thought it was a bit clumsy but assumed if I didn't have # the functions would be interpreted as a text string.
I will experiment but I think you are suggesting I take the " out too.