0

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.

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by jumboora
0

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?

0

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.

0

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();
                }

            }

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.