[Tutor] help with reading a string?
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Jul 16 19:37:31 EDT 2018
On 16/07/18 23:28, Crystal Frommert wrote:
> are learning how to read from a txt file and search for a string.
>
> Here is a sample of text from the txt file:
> TX,F,1910,Mary,895
> TX,F,1910,Ruby,314
> TX,F,1910,Annie,277
>
> How do they read the number after a certain searched name and then add up
> the numbers after each time the name occurs?
>
> I would really like to help them with this code but I am at a loss.
Which bit are you at a loss over?
The general approach is:
open the file for reading
read each line.
search the line for your target string
extract the number at the end of the file
add the number to the running total
None of those are intrinsically difficult, so which
bit are you having problems with?
Have you got any code that you tried and it didn't work?
That would be most helpful in determining where you
need to adjust your approach.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list