Created
April 28, 2012 21:36
-
-
Save mourawaldson/2522244 to your computer and use it in GitHub Desktop.
Split em Java ME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final static String[] split(String texto, char separador) { | |
if (texto == null) | |
return null; | |
int tamanhoTexto = texto.length(); | |
if(tamanhoTexto == 0) | |
return null; | |
Vector lista = new Vector(); | |
int i = 0; | |
int start = 0; | |
boolean permite = false; | |
while(i < tamanhoTexto) { | |
if(texto.charAt(i) == separador) { | |
if(permite) { | |
lista.addElement(texto.substring(start, i).trim()); | |
permite = false; | |
} | |
start = ++i; | |
continue; | |
} | |
permite = true; | |
i++; | |
} | |
if(permite) | |
lista.addElement(texto.substring( start, i).trim()); | |
String[] listaElementos = new String[lista.size()]; | |
lista.copyInto(listaElementos); | |
return listaElementos; | |
} | |
/*Este código não é de minha autoria, estou apenas divulgando para colaborar com os que precisarem fazer uso, caso alguém saiba da fonte, pois não lembro onde conseguí, darei os créditos com toda satisfação.*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment