Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

split jTextArea text to columns  RSS feed

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have jTextArea which accepts numerical data.
I would like to ask how can I split the column 3 and 4

as shown here:
 
Campbell Ritchie
Sheriff
Posts: 54567
150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have thought this question would fit better in a different forum from IO.

There are several ways you can split the String. One is to use String#split() (try "\\s+" as the regex: it means any number of whitespace characters greater than 0).
Try repeatedly testing for the number following. You can create a Scanner passing the String to its constructor and then repeatedly query whether it has a next double.
It all depends on how many numbers you expect to find in the text and how many you want to display.
The String#format() method might be a good way to create the display.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Campbell Ritchie Thank you for your reply.  String#format() method and split("\\s+") helped to divide the columns. Additional, I have used regex to parse double.
 
Campbell Ritchie
Sheriff
Posts: 54567
150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done and thank you for telling us the solution you used.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!