Originariamente inviato da javamen
Il problema lo potete risolvere con la classe StringTokenizer
nel package java.util
un esempio delle api docs
StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
println(st.nextToken());
}
prints the following output:
this
is
a
test
per gestire \n \r ecc.... ecco la descrizione di uno dei costruttori
StringTokenizer
public StringTokenizer(String str) Constructs a string tokenizer for the specified string. The tokenizer uses the default delimiter set, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Delimiter characters themselves will not be treated as tokens.
Ciao
esattamente...oppure potete ridefinire voi i delimitatori per esempio cosi' :
codice:
String DELIMITERS = " \n\t\r\f;.:";
String s = .....;
StringTokenizer st = new StringTokenizer ( s , DELIMITERS);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
fa esattamente la stessa cosa ma in questo caso delimita anche in seguito ad alcuni segni di punteggiatura come il punto, i due punti e il punto e virgola...naturalmente l'elenco può essere esteso come si vuole...
ciauz!