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] > 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 > > -- > Message posted via http://www.dotnetmonster.com
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 --
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] > 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 > > -- > Message posted via http://www.dotnetmonster.com
Thank you for your help, I will look into it. --
Thank you for your help, I will look into it. --
Cordell, Thank you so much for your help, I will test it and let you know. Vicky --
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! --
[quoted text, click to view] Vicky via DotNetMonster.com <forum@DotNetMonster.com> wrote: > 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.
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
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(); } } } --
Don't see what you're looking for? Try a search.
|