Results 1 to 3 of 3

Thread: [2.0] How to get the number of lines in a text file?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question [2.0] How to get the number of lines in a text file?

    Hello!!

    I have a text file with some lines in it.
    How can I know the number of lines in that file?

    thanks!

    Dekel C.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] How to get the number of lines in a text file?

    Read it in, count the number of \n characters, add one.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] How to get the number of lines in a text file?

    You can't know the number of lines without reading them. The simplest way in .NET 2.0 is:
    Code:
    IO.File.ReadAllLines().Length
    If you actually want to keep the data then you'd assign the result of ReadAllLines to a String() variable and then use the Length property of that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width