• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

split jTextArea text to columns

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done and thank you for telling us the solution you used.
reply
    Bookmark Topic Watch Topic
  • New Topic