Time:
Scotland: Fri, 8:53 pm
Rhode Island: Fri, 3:53 pm
Florida: Fri, 3:53 pm
New Mexico: Fri, 1:53 pm
California: Fri, 12:53 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

CLICK HERE TO GET AUCTION BAR NOW
US$10 per year - Save $100s!
The Fabulously Unfair
WebX Auction Bar. For Ebay etc.
Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!


More information and sign-up.

WebXpertz Hosting.
Custom fit from $5pm. PHP/MySQL
You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!


Please click here for more information

For continued disscussion on this topic : comment out


KH@
03-14-2002, 01:01 AM
What is the ColdFusion equivelent to the backslash used to comment out a character in JavaScript

EG 'don't' is written 'don\'t' so the single quote mark between n and t doesn't get read as (end of string) and mess up the code.



I want to replace a double quote with x and I can't seem to do it. I think I may need to comment out the double quote.

<cfset FORM.field = '#replaceList(FORM.field, """, "x")#'>

or swapping the quote types round

<cfset FORM.field = "#replaceList(FORM.field, '"', 'x')#">

or using # to comment out

<cfset FORM.field = "#replaceList(FORM.field, '#"', 'x')#">

None of the above seem to work.

Do I have to use CF script?

There's got to be some way to do it?

jonsteele
03-14-2002, 06:41 PM
First I don't think you are using the right function (according to cf docs):

ReplaceList(string, list1, list2)

You are not passing lists for the second and third parameter.

To escape a qutoes, enter two sets of quotes. This will do what you want :) :

<cfset field = replace(FORM.field, """", "x")>

Jon

KH@
03-15-2002, 01:34 AM
Thanks John.


The function is correct. field,list of one,list of one

I understand ##

do you mean ""

works the same way ?


Don't bust a gut with this one as I've gone round it. However your answer is worth exploring (for me anyway).

why would "" comment out "

???

jonsteele
03-15-2002, 01:50 AM
Yes...the way to insert a double quote within double quotes is a double double quote. Make sense? :D

This should explain:

"" within double quotes = "
'' within single quotes = '
## within # = #

That's just how it is in ColdFusion. :)

Jon

jonsteele
03-15-2002, 01:51 AM
Yes...the way to insert a double quote within double quotes is a double double quote. Make sense? :D

This should explain:

"" within double quotes = "
'' within single quotes = '
## within # = #

So to have a " in double quotes, you would use: """"
(four double quotes).

That's just how it is in ColdFusion. :)

Jon

KH@
03-15-2002, 10:02 AM
That's great john, I only knew about ##

are there any others apart from ' and "

Also while I've got a brainbox on the line how would I remove line breaks and paragraph breaks from a text string?

eg. when the string is from a textarea box and the visitor has included them even though it tells you not to in ten foot letters. :rolleyes:

jonsteele
03-15-2002, 03:20 PM
The char(x) values for line breaks are chr(10) and chr(13) (/n and /r).

So you could use:

replace(string, char(10), "-")
replace(string, char(13), "-")

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.
--------------------------------------------------------------------------------

Error resolving parameter CHAR

KH@
03-15-2002, 07:23 PM
daString = "#replace(daString, chr(10), "-")#"
daString = "#replace(daString, chr(13), "-")#"

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#">

<!--- 1. convert line breaks --->
<cfset daString = "#replace(daString, chr(10), "-")#">
<cfset daString = "#replace(daString, chr(13), "-")#">
<cfset daString = "#replace(daString, chr(14), "-")#">
<!--- 1a. needed to convert line breaks again --->
<cfset daString = "#replace(daString, chr(10), "-")#">
<cfset daString = "#replace(daString, chr(13), "-")#">
<cfset daString = "#replace(daString, chr(14), "-")#">
<!--- 1b. hit it with sledgehammer --->
<cfset daString = "#replace(daString, chr(10), "-")#">
<cfset daString = "#replace(daString, chr(13), "-")#">
<cfset daString = "#replace(daString, chr(14), "-")#">

<!--- 2. convert / " ' --->
<cfset daString = "#replaceList(daString, "',\,""", " ,-,-")#">

<!--- 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.

<cfset daString2 = replace(daString, chr(10), "-")>

Jon

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.

It would make things easier for sure.

Thanks for the help and the pointers Jon