Hi,
I want to process a text file. Here are the contents of the text file

labels 1 -1
-1 0.2988 0.7012
-1 0.188161 0.811839
-1 0.0824541 0.917546
1 0.579515 0.420485
-1 0.0965063 0.903494
-1 0.174624 0.825376
-1 0.0404312 0.959569
-1 0.0770909 0.922909
-1 0.12001 0.87999
1 0.778388 0.221612

In the above data, there are 11 lines (rows) and 3 values (columns) are on each line and every value is separated by a space. The second are third column are actually the probability scores.
Now I want to perform 2 actions.
1. I want to access the second column of each line and print those values into a new text file.
2. I want to analyse second and third column and want to print the highest value in between them into a new text file.

Please help me out to solve this problem.

Do you know how to open a file?
Do you know how to split strings?
Do you know how to convert strings to other types?
Have you done any work at all?

Good question Momerath, but I doubt, otherwise, he wouldnt ask us. Its quite some code, if you want it to make it up for you.
Tell us what you know already, so you make it easier for us.

You both are right....I tried it few times and got the solution...Here it is...

string path = @"F:\TestFile.txt";

            FileInfo fileInfo = new FileInfo(path);

            using (StreamReader streamReader = fileInfo.OpenText())
            {
                string line;

                while ((line = streamReader.ReadLine()) != null)
                {
                    string[] items = line.Split(' ');
                    float myInteger = float.Parse(items[1]);
                    StreamWriter file = new StreamWriter(@"F:\test.txt", true);
                    file.WriteLine(myInteger);
                    file.Close();
                }

            }
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.