Skip to content

Instantly share code, notes, and snippets.

@orejuelajd
Created December 23, 2016 05:29
Show Gist options
  • Save orejuelajd/fc0e93c14466b9a57d5a84b615825fd3 to your computer and use it in GitHub Desktop.
Save orejuelajd/fc0e93c14466b9a57d5a84b615825fd3 to your computer and use it in GitHub Desktop.
```
/*.
Metodo para realizar un split a una cadena
Parametro de entrada: String data: Es la cadena la cual se le va a acer split.
Parametro de entrada: char separator: Es el caracter que separa los bloques de datos.
Parametro de entrada: int index: Para indicar cual es el bloque de datos.
Parametro de salida: String dataSeparada: Se obtiene el bloque de datos en formato String
*/
String getValue(String data, char separator, int index) {
int found = 0;
int strIndex[] = {
0, -1
};
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment