Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    togliere gli spazi da una stringa

    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

  2. #2

  3. #3

    rr

    si... ma per togliere i blank... ci sarà ben un
    istruzione Like "C" es "RTrim" "LTrim" o "Trim" ?
    shd

  4. #4
    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);

  5. #5

    rr

    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

  6. #6

  7. #7

    rr

    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

  8. #8
    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

  9. #9

    La funzione da Me fatta è:

    //-------------------------------------------------------------------------------------
    // @@@ 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

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.