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

Convert ’ to an apostrophe

Contributor ,
Feb 15, 2012 Feb 15, 2012

Copy link to clipboard

Copied

From an XML , the curly apostrophe is rendered as : ’, and displayed as ? (unknown)

because my server and Cf are in ISO--8859-1.

As this is an included file,

I cannot use the tags :

<cfprocessingdirective pageEncoding="UTF-8">

<cfcontent type="text/html; charset=UTF-8">

I only needs it for a small piece of text dipslayed. Not the whole page.

I searched for hours, I did not find any solution to convert the ’ to a single apostrophe.

I tried :

<cfset title=#replacenocase(title,'’',"'","all")#>  does not do anything.

I tried :

<cfscript>

          s="#title#";

          chr_current="UTF-8";

          chr_new="ISO-8859-1";

          

          c=createobject("java", "java.lang.String").init(s);

          convstring=createobject("java", "java.lang.String").init(c.getbytes(chr_current),chr_new).tostring();

        

          title=convstring;

</cfscript>  does not do anything.

I tried :

<cfset title=#replacenocase(title,"’","'","all")#> does not do anything. Because the char found is : ’

Thanks for any help.

More general question is :

How to convert a piece of text from UTF-8  to  ISO--8859-1 ?   not the whole page, because text coming from the DB is

stored as  ISO--8859-1.

TOPICS
Advanced techniques

Views

3.0K

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

correct answers 1 Correct answer

Contributor , Feb 15, 2012 Feb 15, 2012

I found the solution,

I did the replacement at the beginning :

<cfhttp url="#xml_file#" method="GET">

</cfhttp>

<cfset content=#CFHTTP.FileContent#>

<cfset content=#replacenocase(content,"’","'","all")#>

and not after the  XmlParse

Votes

Translate

Translate
Contributor ,
Feb 15, 2012 Feb 15, 2012

Copy link to clipboard

Copied

As I cannot update my question above, I add this : the original code from the XML code is :

<title><![CDATA[Sven Yrvind : un ketch de 15 pieds à travers l’Atlantique !]]></title>

If I take only : title=Sven Yrvind : un ketch de 15 pieds à travers l’AtlantiqueÂ

and use : <cfset title=#replacenocase(title,'’',"'","all")#>

Then it does work.

The <![CDATA[   make this replacement not working.

Thanks for any Help .

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
Contributor ,
Feb 15, 2012 Feb 15, 2012

Copy link to clipboard

Copied

I found the solution,

I did the replacement at the beginning :

<cfhttp url="#xml_file#" method="GET">

</cfhttp>

<cfset content=#CFHTTP.FileContent#>

<cfset content=#replacenocase(content,"’","'","all")#>

and not after the  XmlParse

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
Community Expert ,
Feb 17, 2012 Feb 17, 2012

Copy link to clipboard

Copied

LATEST

plarts wrote:

<cfset content=#CFHTTP.FileContent#>

<cfset content=#replacenocase(content,"’","'","all")#>

This suggesion adds nothing to the discussion, but will make your code neater and more maintainable:

<cfset content=CFHTTP.FileContent>

<cfset content=replacenocase(content,"’","'","all")>

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