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>