473,387 Members | 1,520 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,387 software developers and data experts.

Usage of StreamReader like C++ >>

I am migrating a program from C++ to C# and have encountered a difficulty in
reading the data files. For example, when the data file looks like the
following:

75000 77270
7900 8030

*Note that the spacing between the numbers are tabs, and there is a return
between subsiquent lines.

The C++ code to read this is the following:

ifstream InputFile("ActInput.inp");
InputFile >> SpadaVol[0] >> SpadaMaxVol;
InputFile >> ChapVol[0] >> ChapMaxVol;

I understand the use of StreamReader to read a line, as there are many posts
and instructions on that topic, but I am unable to find a methodology to read
tab delimited or space seperated files (with a variable or consistent number
of spaces). Most annoyingly, there is a broken link in a post to a csv (and
apparently tab delimited) file reader.
Nov 17 '05 #1
2 2457
Can you be more specific on where the broken link was pointing to? It's
possible that it's to a site of mine, or that I would know what was on
it. Also, I sell a csv parser that would fit the bill,
http://www.csvreader.com . My methodology is a complex one based on
speed and a state machine that handles text qualifiers, and escaping
within the data if for instance there's a tab inside one of your cells.
The simple answer to your question is to do ReadLine to read in the
file, and use Split to split based on each occurance of a tab, but like
I said, this method wouldn't handle proper delimited files such as csv.

Ben Enfield wrote:
I am migrating a program from C++ to C# and have encountered a difficulty in
reading the data files. For example, when the data file looks like the
following:

75000 77270
7900 8030

*Note that the spacing between the numbers are tabs, and there is a return
between subsiquent lines.

The C++ code to read this is the following:

ifstream InputFile("ActInput.inp");
InputFile >> SpadaVol[0] >> SpadaMaxVol;
InputFile >> ChapVol[0] >> ChapMaxVol;

I understand the use of StreamReader to read a line, as there are many posts
and instructions on that topic, but I am unable to find a methodology to read
tab delimited or space seperated files (with a variable or consistent number
of spaces). Most annoyingly, there is a broken link in a post to a csv (and
apparently tab delimited) file reader.


Nov 17 '05 #2
Hi,

Go to www.opennetcf.org they have a free CSV data provider.

I dont remember if they handle the TAB as a field separator though

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ben Enfield" <Ben En*****@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
I am migrating a program from C++ to C# and have encountered a difficulty
in
reading the data files. For example, when the data file looks like the
following:

75000 77270
7900 8030

*Note that the spacing between the numbers are tabs, and there is a return
between subsiquent lines.

The C++ code to read this is the following:

ifstream InputFile("ActInput.inp");
InputFile >> SpadaVol[0] >> SpadaMaxVol;
InputFile >> ChapVol[0] >> ChapMaxVol;

I understand the use of StreamReader to read a line, as there are many
posts
and instructions on that topic, but I am unable to find a methodology to
read
tab delimited or space seperated files (with a variable or consistent
number
of spaces). Most annoyingly, there is a broken link in a post to a csv
(and
apparently tab delimited) file reader.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest...
9
by: Howard | last post by:
Hello I need some help with this. I want to assign the content of a static txt/html file to my string a. <script runat="server" language="C#"> private void Page_Load(object sender,...
4
by: Carsten Kraft | last post by:
Hello Newsgroup, I think this is easy for you: I want to save the data line by line into an string array. eg. Text file: Array Line 1 Line1
7
by: Hareth | last post by:
How do I open a file (such as .txt) in C#..... I tried: String File; File = txtMain.Text; dlgOpen.ShowDialog(); File = dlgOpen.FileName;
3
by: David | last post by:
hello... i've a little problem here... n00b question -)) so if you can help me... the "output" string bellow, comes in UNICODE, but i want to get it on windows-1251 (cytillic) how can i do...
2
by: Lukasz Lacki | last post by:
i want to convert string to base64 byte array. i've got problem with it, class Convert is not very helpfull for me. how make such converion in simplest way (input = string / output = byte...
4
by: David Lozzi | last post by:
Howdy, I'm using a WYSIWYG editor called TinyMCE. When I edit some text and then save it back to my SQL server using a SQLCommand, all HTML characters are changed to HTML code, i.e. &gt;strong&lt;...
5
by: Alex Maghen | last post by:
I frequently find myself wanting to insert some basic client-side JavaScript functions in the page of an ASPX of mine. But I find it so frustrating that I have to actually contruct my JavaScript in...
4
by: Kevin Blount | last post by:
As mentioned before, I'm creating a multi-lingual page where the text of the page comes from a database. This page includes a registration form which asks for address information, including the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.