• 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

checking file line's validity

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading from a file, and storing it into an array. Each line must have the format of

SSN|first|last|grade\humCredits|gpa

If there a student with invalid info, I am supposed to reject it and store the rest into the array.

It must have a boolean return value. I have written a basic definition, but I can't see to figure how to reject invalid text fle line, and get to the next line.

Any ideas?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what you mean by "invalid".
I would be tempted to use String.split() method and check the size of the returned array.
 
kenji mapes
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By "invalid" I mean not folowing the above format.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kenji mapes:
By "invalid" I mean not folowing the above format.



Satou was probably referring to the specifics of the above format. For example, is SSN a number or can it contain letters? if number, what is the valid range? Can the first and last name contain numbers? What is a valid grade? etc.

Anyway, if all you are concerned with is the number of fields, that are separated by a specific delimiter, then probably using split() is best -- as you also want an array of the components.

Henry
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, it is still unclear. Looking at the above format does not explain the requirements.
Do you mean :
1. Each items must be separated by a "|"
2. grade and humCredits must be separated by a "\"

If so, you can try String.split(). Here is a sample for number 1:
 
kenji mapes
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry the / was a typo.

I have two txt files to process:

One is bad and one is good.


Good one:

123456789|Smith|John|freshman|15|4.0
987654321|Doe|Joe|sophomore|35|3.9
846834676|Wang|Chin|senior|95|3.7
957654321|Russell|June|junior|75|3.5
957654320|Russell|Harold|senior|195|3.2
456789321|Ortiz|Juan|freshman|25|3.8
987123456|Wade|Warren|sophomore|56|2.5
578315853|Ellis|Anita|sophomore|45|3.8

Bad one:

123456789|Smith|John|freshman|15|4.0
987654321|Doe|Joe|sophomore|35|3.9
248615937|Doe|Jane|senior|35|3.9
846834676|Wang|Chin|senior|95|3.7
9jtd85765|Duval|Janice|senior|100|3.7
957654321|Russell|June|junior|75|3.5
957654320|Russell|Harold|senior|195|3.2
456789321|Ortiz|Juan|freshman|25|3.8
519372486|Fields|Alice
987123456|Wade|Warren|sophomore|56|2.5
578315853|Ellis|Anita|sophomore|45|3.8


So I was not given too much criteria on what to check for, only to check the "format." So, from the providd files, it appears an invallid format, would be one without all the proper field regardless of the characters, etc.

So how would I check? Maybe number of delimeters? i was also thinking that I could put it into the array, and then just delete it?

thanks for your help guys.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So how would I check? Maybe number of delimeters? i was also thinking that I could put it into the array, and then just delete it?



Please refer to the sample I have posted then.
It will return an array. You can then check the number of items in it.
reply
    Bookmark Topic Watch Topic
  • New Topic