Special character not recognized

2019-08-24 08:40发布

问题:

It seems as though he special characters are all recognized as the same thing on my system. Here is some sample code:

// Function that processes a string to put to lowercase and remove special characters
function NormalizeString(s){
    var r=s.toLowerCase();
    if(r.indexOf('é')!=0){
       r=Left(r,r.indexOf('é')) + 'e' +  Right(r,r.length-r.indexOf('é')-1)
    }        
    return r;  
  }

This works and changes the é to an e. Now if I add to this program :

// Function that processes a string to put to lowercase and remove special characters
function NormalizeString(s){
    var r=s.toLowerCase();
    if(r.indexOf('é')!=0){
       r=Left(r,r.indexOf('é')) + 'e' +  Right(r,r.length-r.indexOf('é')-1)
    }  
   if(r.indexOf('ô')!=0){
       r=Left(r,r.indexOf('ô')) + 'o' +  Right(r,r.length-r.indexOf('ô')-1)
    }       
    return r;  
  }

This changes 'Contrôle' to 'ocontrele'. And then I rtied the following code:

function NormalizeString(s){
    var r=s.toLowerCase();
   if(r.indexOf('ô')!=0){
       r=Left(r,r.indexOf('é')) + 'o' +  Right(r,r.length-r.indexOf('ô')-1)
    }       
    return r;  
  }

And it changes 'Contrôle' to 'controle'. I don't get it :(

I am not sure where this problem comes from so I will explain my setup as best I can. I have an HTML page that uses client side java script to query a db on a hard rive. The db is on access 2003 I am using ADO to connect and query. the page is always displayed using ie, but the same problem I describe here happens if i try to open it in Firefox. I am running windows xp with English Canadian settings. I have the line <meta charset="utf-8"> right after the <head> tag of my page.
Please ask if you think more info could elude the mystery.

[EDIT] Also, when I try to write "é" just with normal html, it ouput and small square. I set the font to Arial sans-serif...

回答1:

Sometimes it helps to add an encoding when you include a script into a web page.

<script type="text/javascript" src="myscripts.js" charset="UTF-8"></script>