I have line
word0, word1, word2, word3, word4, ................
I want to break it into array of words a[0]=word0, a[1]=word1, etc
I was trying to use split with reg expression, but with no luck...
can someone suggest an easy approach. thx
Jeffrey Schwab - 24 Jun 2006 01:20 GMT
> I have line
>
[quoted text clipped - 5 lines]
>
> can someone suggest an easy approach. thx
public class Main {
public static void main(String[] args) {
String line = "word0, word1, word2, word3, word4";
String[] a = line.split(",\\s*");
System.out.println(a[0]); // word0
System.out.println(a[1]); // word1
}
}
Timo Stamm - 24 Jun 2006 02:36 GMT
puzzlecracker schrieb:
> I have line
>
[quoted text clipped - 5 lines]
>
> can someone suggest an easy approach. thx
See java.text.BreakIterator
John O'Conner - 24 Jun 2006 15:28 GMT
> puzzlecracker schrieb:
>> I have line
[quoted text clipped - 8 lines]
>
> See java.text.BreakIterator
If that proves too difficult for the original poster, I suggest they
look at String.split().
--
John O'Conner
Timo Stamm - 24 Jun 2006 16:42 GMT
John O'Conner schrieb:
>> puzzlecracker schrieb:
>>> I have line
[quoted text clipped - 11 lines]
> If that proves too difficult for the original poster, I suggest they
> look at String.split().
I think he already did:
| I was trying to use split with reg expression, but with no luck...
Rob - 24 Jun 2006 16:42 GMT
> I have line
>
[quoted text clipped - 5 lines]
>
> can someone suggest an easy approach. thx
StringTokenizer