Bonjour,

Voici le script qui étend l'objet string grâce au prototypage:

Pas de problème particulier avec ce script qui supprime les espaces contenus dans la chaîne

Cependant et c'est là l'objet de ma question, l'expression régulière
(/^[\s\xA0]+/, "")

contient \xA0

Je suppose que c'est la représentation du caractère espace mais je ne comprends pas cette représentation
Sans doute est-ce de l'hexadécimal mais alors ce code ne correspond pas au caractère espace

Quelqu'un a une explication ...Merci

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Ajout d'une fonction trim à String</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
//<![CDATA[
 
String.prototype.trim = function() {
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
 
var sObj = new String("  La chaîne testée t   ");
sTxt = sObj.trim();
 
document.writeln("--" + sTxt + "--");
 
//]]>
</script>
</body>
</html>