File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Process Text from JTextArea" Watch "Process Text from JTextArea" New topic

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,

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

Joined: Oct 29, 2001
Posts: 9168

You can use a 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.

[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.
wood burning stoves
subject: Process Text from JTextArea
It's not a secret anymore!