Hello,

I want to read a txt file, extract some of the fields and insert that in d/b.

Problem- my txt file does not have a fomat, all I know is I want to extract row 29 from col 6to 9. I am using C#.net for this.

Thanks in advance,
-A

Recommended Answers

All 6 Replies

use a readline down to row 29, then however your columns are delimited, read 6 through 9

what piece are you having trouble with, please post the code

use a readline down to row 29, then however your columns are delimited, read 6 through 9

what piece are you having trouble with, please post the code

    StreamReader reader = File.OpenText("C:\\test.txt");  
    string line = reader.ReadLine();           

        while (line != null)
        {

            // string[] stationtxt = line.Split('\t');

            string name = line.Split('\t')[0];
            string url = line.Split('\t')[1];
            string desc = line.Split('\t')[2];

            line = reader.ReadLine();
                           TextBox1.Text = url.ToString();

        }

        reader.Close();
        reader.Dispose();

This is just by trial code, but I am not able to figure out how to navigate to row 29 and get col6 to col9 info.
I am a newbee here, so plz exuse if this is too simple.
-Thanks
A

Please enclose the code in code brackets

int curLine = 0;
while (line != null)
{
curLine++;

if(curLine == 29)
{
//we are on line 29
}

// string[] stationtxt = line.Split('\t');

string name = line.Split('\t')[0];
string url = line.Split('\t')[1];
string desc = line.Split('\t')[2];

line = reader.ReadLine();
TextBox1.Text = url.ToString();

}

i don't know what col6-9 is, you are only showing three columns, but that is how it get the line number

Please enclose the code in code brackets

int curLine = 0;
while (line != null)
{
curLine++;

if(curLine == 29)
{
//we are on line 29
}

// string[] stationtxt = line.Split('\t');

string name = line.Split('\t')[0];
string url = line.Split('\t')[1];
string desc = line.Split('\t')[2];

line = reader.ReadLine();
TextBox1.Text = url.ToString();

}

i don't know what col6-9 is, you are only showing three columns, but that is how it get the line number

Thanks, I figured that out.
Thanks again,
-A

please can you provide me with source code on how to read .txt file using C

thank you

please can you provide me with source code on how to read .txt file using C

thank you

1.It is a bad think to open old thread on any forum and specially here where you just begging for code
2. Forum has following announcement We only give homework help to those who show effort
3.Quick search on google would brought you tons of resources
4. Thread closed. So you better start new thread, but keep in my what I stated above...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.