Skip to content

Instantly share code, notes, and snippets.

@mourawaldson
Created April 28, 2012 21:36
Show Gist options
  • Save mourawaldson/2522244 to your computer and use it in GitHub Desktop.
Save mourawaldson/2522244 to your computer and use it in GitHub Desktop.
Split em Java ME
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