Re: add numbers in file

Tech-Archive recommends: Fix windows errors by optimizing your registry



Here are the very basics to get you started
this will open a file with specified path and name of settings.txt
StreamReader sr1 = File.OpenText( path + \\settings.txt);
String input;
//read through file and retreive info
string st = "";
while ((input=sr1.ReadLine())!=null)
{
st = input;
from here you just need to parse the string value held in st to look for
your field. I don't know what to tell you here, if its a space delimited
field then its really easy as all you have to do is give it a start and end
location through the use of the st.substring function to grab what you need.
Then to do the cast to the double for the purposes of adding up your values
you can use the Convert function...
}

good luck,

"microsoft.news.com" <CSharpCoder> wrote in message
news:eCajtI0RFHA.580@xxxxxxxxxxxxxxxxxxxxxxx
> since i never done this before, do you have a snippet or can you point me
to
> an example of this being done?
>
>
> "glenn" <ghan***@xxxxxxxxxxxxxxxxxx> wrote in message
> news:unD$NE0RFHA.248@xxxxxxxxxxxxxxxxxxxxxxx
> > I'm not quite sure I follow the question here but I'll take a stab. If
I
> > don't understand then I'm sorry.
> >
> > First of all there is no way to just ask the computer what the total is
> for
> > column 2. However, you can write a function that will open the text
file,
> > read the file in one line at the time, grabbing the second column and
> > converting it to a double or currency and then getting the next line.
> >
> > The text file is going to read in a string for each line that you will
> have
> > to parse to get to the 2nd column which looks quite easy if this is the
> > format of your file. But you still have a string when you parse it so
you
> > will need to cast it as a double or currency in order to add it up as a
> > number value.
> >
> > So from my point of view the problem is quite easily obtainable.
> >
> > Good luck,
> >
> > glenn
> >
> > "microsoft.news.com" <CSharpCoder> wrote in message
> > news:uXICU0zRFHA.3052@xxxxxxxxxxxxxxxxxxxxxxx
> > > I have a text file that has a column of numbers that i need to add to
> get
> > a
> > > total of. Is there any way to add the number column in my text file?
> > >
> > > the text file looks like this:
> > >
> > > BMW 25,252.00 1/1/2005
> > > BMW 19,000.00 3/15/2005
> > >
> > >
> > > I need to add the money colum to get 44,252.00. is that even possible
> from
> > a
> > > text file?
> > >
> > >
> >
> >
>
>


.


Quantcast