Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I hava a .txt file with records listed shown below :
how would I read the lines between the CV and End line?
Thanks in advance .




CV 1
Surname:Smith
First Name:John
Address:1 Whatever Street
Qualification:Degree in Computer Science
Position:Data Analyst
Experience:5
Position:Computer programmer
Experience:2
eMail:smithj@gmail.com
End
CV 2
Surname:Harrison
FirstName:Jane
Qualification:None
eMail:harrisonj@gmail.com
End
CV 3
Surname:Jones
First Name:Richard
Address:2 Whatever Street
Qualification:Masters in Computer Science
Position:Operator
Experience:10
Position:Computer programmer
Experience:2
eMail:jonesr@gmail.com
End
CV 4
Surname:Ngomi
FirstName:Mary
Address:3 Whatever Street
Qualification:Degree in Computer Science
Position:Programmer
Experience:10
eMail:ngomim@gmail.com
End

What I have tried:

I have done a while hasnextline loop but that takes the whole file and I want just the section between cv and end.
Posted
Updated 22-Dec-20 19:55pm

1 solution

Depends on the language you are using, but basically it's the same as you would do manually:

1) Read lines until you get one starting "CV ". When you find it create a new collection to hold the lines you wanted (or empty any existing collection)
2) Read lines until you get one that is "End". If it doesn't match, add it to a collection of some form.
3) When it does match, process the collection.
4) Go back to (1) for the next set of lines. until you run out of file.

With no idea what language you intend to write this in that's pretty much all we can do...
 
Share this answer
 
Comments
CPallini 23-Dec-20 2:09am    
5.
grapape808 23-Dec-20 20:46pm    
Thanks, I'm going to look into trying that.
I am using java
grapape808 23-Dec-20 20:58pm    
when you say collection are you referring to arrays? I need to extract the information next to the ":" character can I use a delimiter if I store each block of the file into an array?
OriginalGriff 24-Dec-20 1:51am    
An array is a collection, yes - but there are others. Arrays are a fixed size: once you create it you can't add of remove rows, so unless you know at the beginning how many "blocks" there are in your file - and that's not normally the case - it's best to look at other possibilities. For example, there is the ArrayList:
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
Which allows you to expand it as needed (though at a cost).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900