• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem with "replace"

Guest
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

I use this code to replace characters in a TEXT.

<!--- escape TEXT --->
<CFSET t1 = Replace("#text#","&","&","ALL")>
<CFSET t2 = Replace("#t1#","'","&apos;","ALL")>
<CFSET t3 = Replace("#t2#","""","&quot;","ALL")>
<CFSET t4 = Replace("#t3#","<","&lt;","ALL")>
<CFSET t5 = Replace("#t4#",">","&gt;","ALL")>
<CFSET t6 = Replace("#t5#","‘","&apos;","ALL")>
<CFSET t7 = Replace("#t6#","’","&apos;","ALL")>
<CFSET t8 = Replace("#t7#","“","&quot;","ALL")>
<CFSET t9 = Replace("#t8#","”","&quot;","ALL")>
<cfset e_text = "#t9#">

It work with all characters but not with the following: ‘ ’ “ ”

<CFSET t6 = Replace("#t5#","‘","&apos;","ALL")>
<CFSET t7 = Replace("#t6#","’","&apos;","ALL")>
<CFSET t8 = Replace("#t7#","“","&quot;","ALL")>
<CFSET t9 = Replace("#t8#","”","&quot;","ALL")>

The ones that usually use WORD. I tried also to put chr(X) instead of the characters but doesn't work either.

Any suggestion ?
TOPICS
Advanced techniques

Views

658

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

quote:

Originally posted by: GiambattistaScivoletto
... ...
Any suggestion ?


I suggest you go back and thank the dozens of people who have attempted to help you, in these forums, and that you mark threads answered as appropriate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

If you are trying to replace double quotes, you might have to quote them with single quotes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

quote:

Originally posted by: Dan Bracuk
If you are trying to replace double quotes, you might have to quote them with single quotes.


Yes, of course I tried already that. They are not quotes or double quotes, but the similar ones that use WORD.
Look carefully: ‘ ’ “ ”

chr(145), chr(146), chr(147), chr(148)
[I tried also to use theirs Ascii code to replace, nothing]

Could it be that the problem comes from the fact that the file where I try to replace them is in UTF-8 while the database field where they are selected from is in LATIN ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

cflib has a demoronize() function that's supposed to replace the MS-Word "smart quotes" with regular quotes. Might want to check it out. Even if you don't use the function itself, you can look at the code and see specifically what specific ASCII codes you'd need to use.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 01, 2006 Dec 01, 2006

Copy link to clipboard

Copied

LATEST
Thank you Charlie. I'll check it.

I found out a weird thing.

The code I posted is part of a script that output a XML file that need those characters to be escaped.
The XML file I obtain in output does not have those chars escaped.

BUT, if I try to output the fields where there is the text I need to escape, without the XML schema, then the code I used work.

It doesn't work inside the XML schema. I'm going crazy ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation