• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tokenizing a line and searching

 
Ryan Akim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to write and read from a 'database-like text file.
I'm simply trying to search through the text file for a certain value, the student ID.
Each line represents one student. The format looks like:

etc

I'm basically trying to find a student by their student ID.
My current attempt doesn't seem to work so well:



This current method is a result of me messing around with it and changing things at random.
My main problem is: it always returns the last student in the file, and I can't seem to figure it out.
I'm sure it has something to do with my logic. I'm pretty tired at the moment, so this is getting harder and harder by the hour, haha.

Anyone see the problem?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I m not sure exactly what you search here ? If you found "studentID" , then break the loop.



there is no information that is stored in the loop except "count".
 
Vivek Kr Singh
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scanner will be surely helpful. Use pattern matching to get the line with student id.
 
Ryan Akim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thanks for the reply.
That would work and it would be convenient; however, my professor pretty much forbids the use of break statements anywhere outside of switch() statements. :/

EDIT: I will look into Scanner and matching thanks for the reply.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!