break line into words

P

puzzlecracker

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
 
J

Jeffrey Schwab

puzzlecracker said:
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

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
}
}
 
T

Timo Stamm

puzzlecracker said:
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

See java.text.BreakIterator
 
J

John O'Conner

Timo said:
puzzlecracker said:
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

See java.text.BreakIterator


If that proves too difficult for the original poster, I suggest they
look at String.split().
 
R

Rob

puzzlecracker said:
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

StringTokenizer
 
T

Timo Stamm

John said:
Timo said:
puzzlecracker said:
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

See java.text.BreakIterator


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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top