Oppure (by IroN@xiD)codice:function cerca(stringa,car) L=stringa._lenght R=0 P=0 if(L>0){ for(I=1;I<=L;i++){ if(substring(stringa,I,1)==car){ R+=1 P=I+"; " } } trace("ripetizioni"+R) trace("posizione del carattere "+P ) } stringa = "il mio cane è bello!" car = "è" cerca(stringa,car)
oppure (by Andr3a)codice:function findStrPos(my_str,find_str) { var start_idx=0, posizione=[], tmp; while((tmp=my_str.indexOf(find_str, start_idx))!=-1) { posizione.push(tmp); start_idx=tmp+find_str.length; } return posizione; } Ecco come usarla str="pippo pluto pippo pluto pluto pippo"; var findpos=findStrPos(str,"pippo"); //stampiamo le posizioni individuate for(x=0;x<findpos.length;x++) trace(findpos[x]);
codice:se non ti servono le posizioni ma un highligh o il numero di occorrenze puoi usare questa occorrenze = testo.split(parola).length - 1; oppure testo = testo.split(parola).join(''+parola+'');
Se hai F7
codice:TextField.replaceText() Availability Flash Player 7. Usage my_txt.replaceText(beginIndex:Number, endIndex:Number, text:String) : Void Description Method; replaces a range of characters, specified by the beginIndex and endIndex parameters, in the specified text field with the contents of the text parameter. Example The following example creates a text field called my_txt and assigns the text dog@house.net to the field. The indexOf() method is used to find the first occurrence of the specified symbol (@). If the symbol is found, the specified text (between the index of 0 and the symbol) replaces with the string bird. If the symbol is not found, an error message is displayed in the Output panel. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 22); my_txt.autoSize = true; my_txt.text = "dog@house.net"; var symbol:String = "@"; var symbolPos:Number = my_txt.text.indexOf(symbol); if (symbolPos>-1) { my_txt.replaceText(0, symbolPos, "bird"); } else { trace("symbol '"+symbol+"' not found."); }
insomma basta fare unapiccola ricerca

Rispondi quotando