Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Split & join

  1. #1

    Split & join

    ciao, e la prima volta che vengo su questo forum, me ne hanno parlato bene, è da poco che ho iniziato a studiare Flash MX 2004 Professional ed ho un problemino devo sostituire un carattere da un testo

    ho fatto cosi

    k = "10,50"
    k.split(",").join(".");
    trace (k)
    ma non funziona qualcuno sa dirmi perchè??

    Grazie

  2. #2
    puoi usare questa funzione prototype:
    codice:
    String.prototype.replace = function() {
    	var arg_search, arg_replace, position;
    	var endText, preText, newText;
    	arg_search = arguments[0];
    	arg_replace = arguments[1];
    	if (arg_search.length == 1) {
    		return this.split(arg_search).join(arg_replace);
    	}
    	position = this.indexOf(arg_search);
    	if (position == -1) {
    		return this;
    	}
    	endText = this;
    	do {
    		position = endText.indexOf(arg_search);
    		preText = endText.substring(0, position);
    		endText = endText.substring(position+arg_search.length);
    		newText += preText+arg_replace;
    	} while (endText.indexOf(arg_search) != -1);
    	newText += endText;
    	return newText;
    };
    
    
    stringa = "10,50";
    stringaNuova = stringa.replace(',', '.');
    trace("original was: "+stringa);
    trace("replaced is: "+stringaNuova);
    che trovi qui:
    http://www.sephiroth.it/proto_detail.php?id=16

    regalami un oggi da favola...e il domani bhe!?non mi importa se tu 6 con me! ©Ily

  3. #3
    Effettivamente quella prototype è piuttosto lunga, il metodo di Emiliano concettualmente è giusto, infatti

    k = "10,50"
    k = k.split(",").join(".");
    trace (k)

    Da il risultato che lui voleva , inoltre nei commenti a quella prototype c'è questa

    String.prototype.replace = function(a,b) {
    return this.split(a).join(b);
    }

    che funziona perfettamente ed è molto più comoda

  4. #4
    Originariamente inviato da Broly
    Effettivamente quella prototype è piuttosto lunga, il metodo di Emiliano concettualmente è giusto, infatti

    k = "10,50"
    k = k.split(",").join(".");
    trace (k)

    Da il risultato che lui voleva , inoltre nei commenti a quella prototype c'è questa

    String.prototype.replace = function(a,b) {
    return this.split(a).join(b);
    }

    che funziona perfettamente ed è molto più comoda
    buongiorno...

    non avevo letto bene

    regalami un oggi da favola...e il domani bhe!?non mi importa se tu 6 con me! ©Ily

  5. #5
    Grazie ad entrambi adesso è perfetto


  6. #6
    Ciao e alla prossima

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.