473,804 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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 2315
r035198x
13,262 MVP
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
someone28485
3 New Member
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(Fi le.OpenRead(@"F :\src.txt"));
string fileContent = sr.ReadToEnd();
sr.Close();

StreamWriter writer = new StreamWriter(Fi le.Create(@"F:\ dest.txt"));
writer.Write(fi leContent);
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 MVP
StreamReader sr = new StreamReader(Fi le.OpenRead(@"F :\src.txt"));
string fileContent = sr.ReadToEnd();
sr.Close();

StreamWriter writer = new StreamWriter(Fi le.Create(@"F:\ dest.txt"));
writer.Write(fi leContent);
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
someone28485
3 New Member
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
3511
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 strings as keys: three, four, five, six - do I add the key names in the file?
1
8165
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 http://www.google.com,Google in to a file. I want the user to be able to send as many links with names as they want to that file. Then I want my program to be able to read from that file as I start the program from a button at my form and use it...
2
6719
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
1598
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 of the following way to do the job: - use xsd.exe to create basic c#-classes from xsd.file (modify these classes according to my particular needs)
1
4312
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 time after routine process A, the text file is named "mytext.dat" in following format with "#####" as separator. The maximum entries of them is 5. When reaching the fifth entry, it will delete the very first entry.
5
3164
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 looks like this: ----- beginning of file ----- 192.168.0.1 0 0 2004-08-01 192.168.0.2 1 0 2004-08-21 192.168.0.4 0 1 2004-08-12
11
11950
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 figure out how to reply to the thread per se using Google Groups and so please forgive me for cutting and pasting (I emailed him but he may not have time to check his email), and I am hoping someone might be able to tell me how I can change this...
5
11281
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 couple areas that have ASCII text that I need to extract. At the end of the 2580 bytes, I can read the report like a standard text file. It should have CR/LF at the end of each line. What is the best way for me to read this report using C#. It is...
63
3271
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 mean=0,linput=0; FILE *fpr, *fpw;
0
10562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.