Jscript: Traitement de CHaine (Help to test)

Fermé
Aki - 28 mai 2002 à 15:37
 AKI - 28 mai 2002 à 15:38
Etant donné qu'il n'existe pas de fonction Trim (suppression des espaces blanc et autres en début et en fin de chaîne en VBSCRIPT) en Jscript.

J'ai fait une fonction (en vitesse, je sais c 'est pas très clair :-)

pouvez vous la testez please, rien de telle qu'un autre programmeur pour faire planter un prog);

function trim(strTrim)
{
var expReg = /[\s]/; // expression à rechercher : espace, tabulation, ...
var blnChar = false;
var strChar;
var intChar;
var strTemp = strTrim;
var intBeginString= -1;
var intEndString='';
// Vérifie si la chaine n'est pas vide
if (typeof(strTemp)!='undefined')
{
// Récupère la taille de la chaîne
var intLength = strTemp.length;
// Check chaque caractère de la chaîne à tester
for (var x=0; x<intLength;x++)
{
strChar = strTemp.substring(x,x+1);
intChar = strChar.search(expReg);
if (intChar==0)
{
if (blnChar==false) intBeginString = x;
else
{
if (intEndString.length==0) intEndString = x;
} // End second if
}
else
{
blnChar=true;
intEndString='';
} // End first if
} // End for

if (intEndString=='') intEndString=intLength;

strTemp = strTemp.substring(intBeginString+1,intEndString);
}
return strTemp;
}

1 réponse

Il a supprimé mes tabulations snirffff
0