In Java code, I want to know how I can separate a text string for each space that exists in it.
In Java code, I want to know how I can separate a text string for each space that exists in it.
Use the split()
method that separates the string with the string specified in the parameter:
String[] datos = "hola mundo como estas".split(" ");
for(String item : datos)
{
System.out.println(item);
}
You can use this function:
is being used on a string S
s="Separar por espacios"
s.split(" ");
The split () function can be used not only for one character but for several.
Example:
String cadena = "texto de que quieras";
String delimitadores= "[ .,;?!¡¿\'\"\[\]]+";
String[] palabrasSeparadas = cadena.split(delimitadores);