0

delete student record from text file

How do i delete a student record from a text file via there student number. I tried using contains. But that only allows for a string amd the student number is an int.

14th Oct 2017, 1:07 PM
Darrian Rajah
Darrian Rajah - avatar
7 Réponses
+ 4
if the student number is part of a text file it will be part of a string. Load each row of the text file in an array of strings Go through the array and if you find a substring that equals the number of the student, delete the corresponding row. According to how the data is structured you may want to check only a defined part of each row to avoid that your program matches the sudent number within, let's say the phone number or the address of another student.
14th Oct 2017, 1:25 PM
seamiki
seamiki - avatar
+ 3
These are examples for storing each line of a text file into strings https://howtodoinjava.com/core-java/io/java-read-file-to-string-examples/ and find a substring within a string http://www.geeksforgeeks.org/searching-for-character-and-substring-in-a-string/
14th Oct 2017, 1:59 PM
seamiki
seamiki - avatar
+ 1
THANKS BRO!!!!
14th Oct 2017, 2:00 PM
Darrian Rajah
Darrian Rajah - avatar
0
have you tried using Hashmaps?
14th Oct 2017, 1:11 PM
Chris Morris
Chris Morris - avatar
0
No, I have no idea how to use that....
14th Oct 2017, 1:12 PM
Darrian Rajah
Darrian Rajah - avatar
0
Would you be able to give me the code for that? I’m really stuck.
14th Oct 2017, 1:52 PM
Darrian Rajah
Darrian Rajah - avatar
0
@seamiki
14th Oct 2017, 1:52 PM
Darrian Rajah
Darrian Rajah - avatar