473,388 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

how to read,modify and write to the text file with numbers in it

hi,i need 2 write code in C#.Net to read a text file with text as

22.13
21.65
25.16
31.22

and so on, i need 2 read this text and then take mean of the 4 values and write that mean result in another file, so far i've only been able to read the whole text from one file and write it to another file,can anyone please help me solve my problem,i.e. how to read values in chunks of four,store them in an array (probably) and then take the mean and send that result to another file.i am facing more prob with the syntax,any help ?
please it's urgent
Nov 15 '07 #1
4 2276
r035198x
13,262 8TB
hi,i need 2 write code in C#.Net to read a text file with text as

22.13
21.65
25.16
31.22

and so on, i need 2 read this text and then take mean of the 4 values and write that mean result in another file, so far i've only been able to read the whole text from one file and write it to another file,can anyone please help me solve my problem,i.e. how to read values in chunks of four,store them in an array (probably) and then take the mean and send that result to another file.i am facing more prob with the syntax,any help ?
please it's urgent
TextReader and TextWriter are your friends here.
Look up their specs for them, try the code and post back if you get errors with it.
Nov 15 '07 #2
TextReader and TextWriter are your friends here.
Look up their specs for them, try the code and post back if you get errors with it.
StreamReader sr = new StreamReader(File.OpenRead(@"F:\src.txt"));
string fileContent = sr.ReadToEnd();
sr.Close();

StreamWriter writer = new StreamWriter(File.Create(@"F:\dest.txt"));
writer.Write(fileContent);
writer.Close();

this is my code that simply reads from src.txt n writes that 2 dest.txt,now my prob is that i donno how to read values in chunks of 4 ,take thei mean and then write the result in another file,itz actually the syntax i get stuck on
Nov 15 '07 #3
r035198x
13,262 8TB
StreamReader sr = new StreamReader(File.OpenRead(@"F:\src.txt"));
string fileContent = sr.ReadToEnd();
sr.Close();

StreamWriter writer = new StreamWriter(File.Create(@"F:\dest.txt"));
writer.Write(fileContent);
writer.Close();

this is my code that simply reads from src.txt n writes that 2 dest.txt,now my prob is that i donno how to read values in chunks of 4 ,take thei mean and then write the result in another file,itz actually the syntax i get stuck on
StreamReader has a ReadLine method. Use that instead of the ReadToEnd method.
As I said, open the specs for those classes and check the methods for yourself.
Also have a look at the StringWriter and StringReader classes
Nov 15 '07 #4
StreamReader has a ReadLine method. Use that instead of the ReadToEnd method.
As I said, open the specs for those classes and check the methods for yourself.
Also have a look at the StringWriter and StringReader classes
altight, thank you. i will look into the specs for these,thnx again:)
Nov 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: deko | last post by:
I have a text file ("eighty.txt") that looks like this: 83|84|85|86 I can read the file into an array like this: $numbers= file("eighty.txt"); But how do I key the array? I'd like to use...
1
by: Jonas | last post by:
I want the user to be able to write like http://www.google.com in one textBox and Google in an other textBox. Than I want the user to press a button when done. The text will then be past like...
2
by: kak3012 | last post by:
Hi, I have a text file I will read it and write out binary. The file includes 256 coloums. I use while (infile.good()) { infile.getline (buffer,2200);
1
by: ezmeralda | last post by:
Hello, I have to solve the following task: - create an editor-application in c# to read, modify and create xml-files - .xsd-schema-file is available and can be used Currently, I am thinking...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
5
by: Martin Svensson | last post by:
Hello! I need some help/recommendations on how to do the following. I have a program that writes an IP address two control numbers and a date to file, on one line. It's a basic text file and it...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
63
by: Bill Cunningham | last post by:
I don't think I can do this without some help or hints. Here is the code I have. #include <stdio.h> #include <stdlib.h> double input(double input) { int count=0,div=0; double...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.