..:: MX Studio Fóruns ::..: Classe para manipulacao de String - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Classe para manipulacao de String flash mx 2004 na veia...

#1 User is offline   Andrews 

  • Group: Membros
  • Posts: 464
  • Joined: 09-February 04

Posted 01 June 2004 - 12:51 PM

Estou mandando pra voces uma classe que pode fazer tudo o que a classe String faz mas com métodos adicionados, para facilitar a manipulacao de Strings no flash

Ela foi feita por mim com a ajuda do Maxwell Dayvson

CODE

/*
Classe Str v1.0
feita para faciliar a manipulacao de Strings
criada por Andrews Medina (cybermix)
auxílio:Maxwell Dayvson
*/
dynamic class Str extends String {

function Str(texto:String) {
 super(texto);
}

public function removeAcento():String {
    var x,str:String=this;
 var lista= {a:['á','ã','à','â'], e:['é','ê','è','ë'],
    i:['í','ì','ï','î'], o:['ó','ô','ò','õ'],u:['ú','ù','ü','û']};
 for (x in lista) {
  for (var i:Number=lista[x].length; i--;) {  
   str = str.split(lista[x][i].toUpperCase()).join(x.toUpperCase());
   str = str.split(lista[x][i]).join(x);
  }
 }
 return(str);
}

public function replace(v:String, n:String):String {
 var r:String = this;
 r = r.split(v).join(n);
 return(r);
}

public function trim():String {
 var i:Number;
 var texto:String = this;
 for (i=0; texto.charAt(i) == " "; i++);
 texto = texto.substr(i, texto.length);
 for (i=texto.length-1; texto.charAt(i) == " "; i--);
 texto = texto.substr(0, i+1);
 return (texto);
}

public function ltrim():String {
 var i:Number;
 var texto:String = this;
 for (i=0; texto.charAt(i) == " "; i++);
 texto = texto.substr(i, texto.length);
 return (texto);
}

public function rtrim():String {
 var i:Number;
 var texto:String = this;
 for (i=texto.length-1; texto.charAt(i) == " "; i--);
 texto = texto.substr(0, i+1);
 return (texto);
}

public function inverte():String {
 var text:String = this;
 return(texto.split("").reverse().join("").toString());
}

public function retEspacos():String {
 var texto:Str = new Str(this);
 return (texto.replace(" ", ""));
}
}


Exemplo do seu uso:

CODE

import Str;
var texto:Str = new Str(" Andrews medina é vicio em flash mx 2004 ");

trace(texto.removeAcento());
trace("<"+texto.trim()+">");
trace("<"+texto.ltrim()+">");
trace("<"+texto.rtrim()+">");
trace(texto.replace("m", "Y"));
trace(texto.inverte());
trace(texto.retEspacos());

//alguns metodos da classe string para verem como é legal =D
trace(texto.indexOf("med", 0));
trace(texto.length);


tongue.gif
0

#2 User is offline   Tatu 

  • Group: Membros
  • Posts: 1124
  • Joined: 06-January 04

Posted 01 June 2004 - 01:17 PM

mandou bem andrews
parabéns
thumbup.gif
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic



Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)