This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Process Text from JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Process Text from JTextArea" Watch "Process Text from JTextArea" New topic
Author

Process Text from JTextArea

celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
Hi Everyone,

I wonder if someone could help me. I'm writing a 'mini-parser' in java for assembly code. Basically, i have a JTextArea where the asm goes. I need to know how to deal with the text from my textArea one line at a time?

I can say: textArea.getText, but this returns all the text. Or i can say getLineStartOffset, getLineEndOffset which gives me one line (usually the first one). But, how do i get the first line via start & end offsets and then move on to the next line and so on until all lines of text are dealt with?

Thanks a million,
Celine


We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br />- Robert Wilensky
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

You can use a java.io.StringReader to read from a String object as if it were ai input stream, then wrap it with a BufferedReader which has a readLine() method. There's other helpful classes like PushbackReader, which allows you to put characters back into the stream you read them from and LineNumberReader, which keeps track of line numbers, which I imagine could be useful when writing a parser.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
That's great Joe. Thanks a million for your help.
Celine
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Process Text from JTextArea