Results 1 to 4 of 4
  1. #1
    Unnel is offline Member
    Join Date
    Nov 2010
    Location
    Johannesburg
    Posts
    23
    Rep Power
    0

    Default How to use the split method with a non-constant delimiter

    Good day,

    I'm trying to read a text file by extracting specific data that are in one line and excluding others on the same line. The data I want to extract are separated by the 'space' delimiter but unfortunately this delimiter was not used uniformly for the entire line, I mean that sometimes data in a line will be separated by a single space for some and sometimes two to three spaces for others.

    How do I change the delimiter for the split method I'm using please so that no matters the space between the data it extracts the correct ones?

    Thanks

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Unnel View Post
    I'm trying to read a text file by extracting specific data that are in one line and excluding others on the same line. The data I want to extract are separated by the 'space' delimiter but unfortunately this delimiter was not used uniformly for the entire line, I mean that sometimes data in a line will be separated by a single space for some and sometimes two to three spaces for others.

    How do I change the delimiter for the split method I'm using please so that no matters the space between the data it extracts the correct ones?
    Can you use the expression "\\s+" (i.e. one or more spaces)?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    you can use use "<space><space>*", if you really want space and left others like tabs alone. Otherwise, if you want tabs (and other whitespaces) to be counted as spaces, use "\\s+"

  4. #4
    Unnel is offline Member
    Join Date
    Nov 2010
    Location
    Johannesburg
    Posts
    23
    Rep Power
    0

    Default

    Thanks, it helped a lot...I got it to work..

    Many thanks :)

Similar Threads

  1. String split method
    By DavidG24 in forum New To Java
    Replies: 5
    Last Post: 12-14-2010, 02:01 PM
  2. String split method
    By counterfox in forum New To Java
    Replies: 2
    Last Post: 11-12-2010, 11:06 PM
  3. Please help me with Split method> String
    By javanew in forum New To Java
    Replies: 5
    Last Post: 04-02-2010, 06:15 PM
  4. split method problem
    By javanew in forum New To Java
    Replies: 1
    Last Post: 04-02-2010, 05:50 PM
  5. problem with split method
    By abhiN in forum New To Java
    Replies: 7
    Last Post: 02-10-2009, 01:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •