Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Process Text from JTextArea

 
celine mcgowan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Ess
Bartender
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
celine mcgowan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great Joe. Thanks a million for your help.
Celine
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic