Groups | Blog | Home
all groups > c# > april 2005 >

c# : help with reading fields in a text file



Ignacio Machin ( .NET/ C# MVP )
4/8/2005 2:36:52 PM
Hi,

Take a look at the CSV data provider from opennetcf.org

cheers,

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



"Vicky via DotNetMonster.com" <forum@nospam.DotNetMonster.com> wrote in
message news:9a0e1fb02f4c40c7aaa011908690b42c@DotNetMonster.com...
[quoted text, click to view]

shriop
4/8/2005 3:11:59 PM
I also sell a csv parser that might make reading this file easier.
There's demo version available on the site.

http://www.geocities.com/shriop/index.html
Vicky via DotNetMonster.com
4/8/2005 6:11:15 PM
Please help with reading fields in a text file.
I need to get the index name, (ticker field in text file),
Please see one file as an example (There are actually 1000 files)

If we open the file, the text includes Header and data
TICKER>,<PER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OPENINT>
..A1DOW,M,19980630,000000,264.2900,264.9700,250.8000,264.2900,0,0
..A1DOW,M,19980731,000000,260.3700,276.5900,260.3700,260.3700,0,0

I need to read the ticker A1DOW and M to console first, (later I will
compare the ticker with existing DB, and load the data.

Thank you for any info, which method I should look into it?
I really appreciated.

Vicky

--
Cordell Lawrence
4/12/2005 1:12:04 PM
A very easy way to read these values from the file will be to use the
String.Split method like so:

StreamReader sr = new StreamReader(filePath);

string currentLine = null;

do
{
currentLine = sr.ReadLine();
string[] data = currentLine.Split(',');

string val1 = data[0];
string val2 = data[1];
// etc.

}while(currentLine != null);

Hope this helps.
Cordell Lawrence
Teleios Systems Ltd.
"Vicky via DotNetMonster.com" <forum@nospam.DotNetMonster.com> wrote in
message news:9a0e1fb02f4c40c7aaa011908690b42c@DotNetMonster.com...
[quoted text, click to view]

Vicky via DotNetMonster.com
4/15/2005 12:00:00 AM
Thank you for your help, I will look into it.

--
Vicky via DotNetMonster.com
4/15/2005 12:00:00 AM
Thank you for your help, I will look into it.

--
Vicky via DotNetMonster.com
4/15/2005 12:00:00 AM
Cordell,

Thank you so much for your help, I will test it and let you know.

Vicky

--
Vicky via DotNetMonster.com
4/22/2005 3:17:56 PM
Cordell,

I tested, everything is working besides I saw error msg said
An exception 'System.NullReferenceException' has occurred in
OpenText.exe

Object reference not set to an instant of an object.

but it still runs, I add the code to print val1 and val2 to the console
so I could see the result, it did print to the console.

Do you have any hint how to modify the code without the msg.

Thanks!

--
Jon Skeet [C# MVP]
4/25/2005 12:00:00 AM
[quoted text, click to view]

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Vicky via DotNetMonster.com
4/25/2005 12:00:00 AM
Jon & Cordell,

I modified the code, it is working for this part now.
I will post a short MSG of this all program later.
Thanks!

using System;
using System.IO;
using System.Text;

class OpenText
{
public static void Main()
{

StreamReader sr = new StreamReader("c:\\USIndex\\_A1DOWM.txt");

string currentLine = null;


currentLine = sr.ReadLine();

currentLine = sr.ReadLine();

while(currentLine != null)
{
string[] data = currentLine.Split(',');

string val1 = data[0];
string val2 = data[1];
// etc.
Console.WriteLine(val1);
Console.WriteLine(val2);

currentLine = sr.ReadLine();
}


}
}

--
AddThis Social Bookmark Button