Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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: 74645
335
  • 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: 74645
335
  • 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