Parse JTextArea in Java

User write something into JTextArea .
I have an array with specified words for example {"name1","name2","name3"}
If i found this words in textarea after the user writed i must put into array all word from line wher i found a word form list.
For example: textarea: name1 1,23,4;
name2 asasas;
name3 jkjkjk;
When i found the word "name1" i must put into array name1 1,23,4
I don't know how i parse all the  lines from textarea and get this information into array.

cipriancomsaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrWarezzCommented:
Hi cipriancomsa,

Firstly, you want to extract the text from the JTextArea, and assign it to a String, like so:

JTextArea jta = new JTextArea();
 . . .
String content = jta.getText();

Then tokenize it to an array of each line, like so:

(Import java.util.*; for this..)

StringTokenizer st = new StringTokenizer( content, "\n" );
String [] lines = new String [ st.countTokens() ];

for ( int i=0; i<st.countTokens(); i++ ) {
   lines[i] = st.nextToken();
}

// Now, you have an array of each line in the text field. Then, you can use the "StringTokenizer" class again, or the split() method to tokenize, and extract other data.

Hope that helps,
[r.D]
0
DrWarezzCommented:
>"When i found the word "name1" i must put into array name1 1,23,4"
Do you need to put into the array "name1 1,23,4"? Or, do you want to put into an array representing "name1" the value "1,23,4"? I'm going to assume the first ...

String [] names = { "name1", "name2", "name3" };

Then, after using the code in my previous comment...

for ( int a=0; a<lines.length; a++ ) {
   for ( int b=0; b<names.length; b++ ) {
      StringTokenizer st1 = new StringTokenizer( lines[a], names[b] );
      while ( String str = st1.nextToken() && str != null ) {
         names [b] = names[b] + str;
      }
   }
}

That *should* work, but I haven't tested it, and kinda rushed it, but it should at least get you on the right track..

gL,
[r.D]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cipriancomsaAuthor Commented:
Thank you for answer.
0
DrWarezzCommented:
8-) ThanQ.
[r.D]
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.