Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read the second line from the text

Tags:

c#

windows-8

how do i read the second line of text in visual studio 2012 c#

         the txt file

         user123
         **12345**
         asdfd

i want to get the second line in one button1_click and show it to textblock2

i did try learn from here How do I read a specified line in a text file?

and here How to skip first line and start reading file from second line in C#

but no one of these works because theres difference i couldnt apply in my code

any help?

================================================================================= sorry to confusing you all actually im really lacking experience in programming and i hardly know how to use it
right now im using vs2012 in windows8 , is that mean i was coding in winrt?

btw , i appreciate all your help and successfully applying answer to my code this is the actual code

        var file = await ApplicationData.Current.LocalFolder.GetFileAsync(tb1.Text+".txt");
        var line = await FileIO.ReadLinesAsync(file);
        if (tb2.Text == line[2])
        {
            tb3.Text = (line[1]);
        }
like image 474
Andy Surya Avatar asked Nov 20 '25 13:11

Andy Surya


1 Answers

var desiredText = File.ReadLines("C:\myfile.txt").ElementAt(1);

File.ReadLines() returns an IEnumerable<String> of the lines in a file. The index of the second line is 1. See this.

like image 137
tallseth Avatar answered Nov 23 '25 01:11

tallseth