Results 1 to 4 of 4
  1. #1
    Tabula Rasa is offline Member
    Join Date
    Apr 2011
    Location
    USA
    Posts
    15
    Rep Power
    0

    Default Reading a File and Ignoring White Space

    How can I read a text file and ignore whitespace?

    I'm using a delimiter to parse commas in the file. When the file content has no spaces, the code runs, but when I put spaces between the words in the file, a NoSuchElement exception is thrown.

    For example, here is a line:

    Jones,Jack,3.5,AppliedMath

    This line is read just fine.

    But if I change it to:

    Jones, Jack, 3.5, Applied Math

    A NoSuchElement exception occurs.
    Last edited by Tabula Rasa; 04-21-2011 at 09:09 AM.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You can read a line, split based on commas and use trim to remove the white space.

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Why not read the line with the spaces and then replace all spaces with the empty string?

  4. #4
    Tabula Rasa is offline Member
    Join Date
    Apr 2011
    Location
    USA
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Okay..I'm waiving the white flag on this
    By velvetymold in forum New To Java
    Replies: 10
    Last Post: 02-22-2011, 07:15 AM
  2. JSTL and HTML White space
    By newakdev in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 02-24-2010, 06:54 PM
  3. compile ignoring dependency errors
    By Geoffrey in forum Java Servlet
    Replies: 1
    Last Post: 09-10-2009, 07:45 PM
  4. [SOLVED] remove all white space from text file
    By loki in forum New To Java
    Replies: 10
    Last Post: 04-26-2009, 12:52 PM
  5. White Space Issue
    By sibythoma1984 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-22-2008, 01:05 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
  •