I have a text file

No.,A ,B ,C ,D ,E ,F ,G
1 ,10,11,13,15,10,15,14
2 ,12,10,15,14,9 ,19,12
. ,..,..,..,..,..,..,..
. ,..,..,..,..,..,..,..
. ,..,..,..,..,..,..,..
. ,..,..,..,..,..,..,..
. ,..,..,..,..,..,..,..
. ,..,..,..,..,..,..,..
n ,..,..,..,..,..,..,..

I would like to sum just A+B+C+D+E+F+G

Then put them in another text file
No. Sum
1, 88
2, 91
., ..
., ..
., ..
., ..
., ..
n, ..

Recommended Answers

All 3 Replies

Hi

What code have you got so far? Show us that and we can help you to break the problem down.

To get you started (if you haven't already), look at using the StreamReader to read your text file. Then the String.Split method to read each number for a line. Do the maths, then use the StreamWriter to write the data back to another file.

Hi
My problem is how split words each line and sum secound number with next.
Then, write just first word with sum.

I am a beginner in C#.
Thanks for help me in advance!

Well, your example shows that each number is separated by a comma, so this is what you would use for the split method. This will give you an array which you can loop around. The first element of that array will be ignored when adding each value together but used when writing to your new file.

Have a go and post your code with info on where it is not working and we can go from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.