CiAO A TUTTI.
Grazie dell' atenzioone
Purtroppo HO 2 Problemi relativi a parametri letti da file :
1) Non so come si fa a togliere gli spazi davanti e dietro la stringa
2) Come si possono togliere i "cr" "lf"?
Help me please!![]()
CiAO A TUTTI.
Grazie dell' atenzioone
Purtroppo HO 2 Problemi relativi a parametri letti da file :
1) Non so come si fa a togliere gli spazi davanti e dietro la stringa
2) Come si possono togliere i "cr" "lf"?
Help me please!![]()
shd
C'è un esempio in fondo a questo articolo:
http://flash-mx.html.it/guide/view_l...guida=9&id=196
si... ma per togliere i blank... ci sarà ben un
istruzione Like "C" es "RTrim" "LTrim" o "Trim" ?
shd
puoi fare così:
codice:strin = "Tanto Va La Gatta Al Lardo Che Ci Lascia Lo Zampino"; strou = ""; for (i=0; i<strin.length; i++) { if (strin.slice(i, i+1) != " ") { strou += strin.slice(i, i+1); } } trace("inp => "+ strin); trace("out => "+ strou);
Grazire x la tua attenzione.
ma con il metodo da te suggeritomi elimino tuti i blank.
tutto cio' non fa' al caso mio .
ovvero io dovrei eliminare il carattere da Dx e SX della stringa passata Ovvero devo implementarmi le funzioni di LtRIM(Left Trim)
e RTrim(Right Trim).
![]()
shd
Potrebbero esserti utili questa -> http://www.sephiroth.it/proto_detail.php?id=15 e questa -> http://www.sephiroth.it/proto_detail.php?id=56
Come si fa a includere nel progetto flash il file.as ?
Ma... tu , cosi' scrivendo hai aggiunto un metodo alla classe
String ? Possibile ? mi dai 2 dritte ? Thanks!
String.prototype.trim = function() <=====
{
var j, strlen, k;
// -----------
// From Begin
// -----------
strlen = this.length
j = 0;
while (this.charAt(j) == " ")
{
j++
}
if(j)
{
this = substring(this,j+1, strlen)
if(j == strlen) return this;
}
// -------------
// From the end
// -------------
var k = this.length - 1;
while(this.charAt(k) == " ")
{
k--
}
this = substring(this,1,k+1)
return this;
}
![]()
shd
Quella prototype non l'ho fatta io![]()
Ti basta comunque incollare il codice nel primo frame del filmato e potrai usare quel metodo per tutte le stringhe del tuo filmato...sì, in pratica usando le prototype aggiungi un metodo ad una classe![]()
//-------------------------------------------------------------------------------------
// @@@ TRIM @@@
// Ver 01 040707
//-------------------------------------------------------------------------------------
// RITORNO : Stringa Trimmata.
// Funzione che elimina alla DX e all' SX della Stringa il carattere passato : sChrToFind
//--- es Utilizzo :
// var sStrProva = " Ciao sono Enrico ";
// sStrProva =Trim(sStrProva,' ');
// ==> Risultato : "Ciao sono Enrico"
function Trim(sSTring,sChrToFind){
var bFoundCharDiv = false;
var iLenStr = sSTring.length;
var iIdxFineStr = iLenStr - 1;
var iCtr = 0;
var sTmp = "";
var iIdx = 0;
// ---- LEFT TRIM CHR ------
bFoundCharDiv = false;
while((iCtr < iLenStr) && (!bFoundCharDiv)){
sTmp = sSTring.charAt(0);
if(sTmp == sChrToFind){// Se Trovo chr ==> mi calcolo substr da chr a fine Str
sSTring = sSTring.substr((1),(iIdxFineStr));
}
else{// Chr not found ==> c'e' gia' un altro chr ==> finito
bFoundCharDiv = true ;
}
iCtr ++;
}
// ---- RIGHT TRIM CHR ------
iLenStr = sSTring.length;
iIdxFineStr = iLenStr - 1;
bFoundCharDiv = false;
for(iIdx = iIdxFineStr; (iIdx >= 0) && (!bFoundCharDiv); iIdx--){
sTmp = sSTring.charAt(iIdx);
if(sTmp == sChrToFind){// Se Trovo chr ==> mi calcolo substr da chr a fine Str
sSTring = sSTring.substr(0,iIdx);// mI COPIO Str da init fino a punto ritrovamento CHR
}else// Chr not found ==> c'e' gia' un altro chr ==> finito
bFoundCharDiv = true;
}
return sSTring;
}
![]()
![]()
![]()
shd