Skip to main content
April 9, 2010
Answered

Replacing Special Characters when writing to a file

  • April 9, 2010
  • 2 replies
  • 1128 views

I am using the following to replace Muñoz  (the ñ with null) .  It should output as Muoz.

This should be simple but it is not working.  209 and 241 represent the upper and lower case ñ.

This statement is in a CFFILE.  I am generating the file but the ñ is still there.

replace(LGL_NM,chr(209)&chr(241),'3','all')

I also tried the following without success:

<cfset x = ReplaceNoCase(#Object_query.LGL_NM#,"#chr(209)#", " ", "all")>
<cfset LGL_NM = ReplaceNoCase(x,"#chr(241)#", " ", "all")>

Please Help.

Thanks!

Bill

    This topic has been closed for replies.
    Correct answer BKBK

    <!--- sets the encoding to UTF-8 --->

    <cfprocessingdirective pageencoding="utf-8">
    <cfset testString="muñaÑoz">

    <!--- Replace any character match in the regular expression [ñÑ] with a blank string--->
    <cfoutput>#REReplaceNoCase(testString, "[#chr(209)##chr(241)#]", "", "all")#</cfoutput>

    2 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    April 11, 2010

    <!--- sets the encoding to UTF-8 --->

    <cfprocessingdirective pageencoding="utf-8">
    <cfset testString="muñaÑoz">

    <!--- Replace any character match in the regular expression [ñÑ] with a blank string--->
    <cfoutput>#REReplaceNoCase(testString, "[#chr(209)##chr(241)#]", "", "all")#</cfoutput>

    April 11, 2010

    Thank You!  That worked!

    Bill

    BKBK
    Community Expert
    Community Expert
    April 12, 2010

    OK. Good luck.

    BreakawayPaul
    Inspiring
    April 9, 2010

    When I try what you pasted, I get "Mu oz" in the file.  The n is missing.  Not sure why it's not working for you.  Maybe a charset thing?  I'm using iso-8859-1

    April 9, 2010

    Thanks for the response Paul.

    Where is the character set defined?  How do I know what I am using?

    Thanks again.

    Bill

    BreakawayPaul
    Inspiring
    April 10, 2010

    I mean on the page itself, in the meta tag.  Not sure if it's what's causing the difference though.

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />