Tipale 2 - Get an ASCII file's Number of lines / last line / line number X

This cool implementation was first introduced to me by the talented Roman Goldenberg, and is one of my favourites.

The task is a simple one, and so is the technique offered by Roman.

Get an ASCII file's:
- Number of lines
- Last line
- Specific line

Roman suggests accessing the lines by simply loading the whole file to Blob, and then handle it as a long CR+LF separated string.

The code should be best placed within a Global Function, thus available to the whole project, as shown in the short video.






May the source be with you
* the source is an export of a project that contains the code for Tipale 1&2

Comments

  1. You can use a .NET snippet to get the number of lines by using Linq:
    var lineCount = File.ReadLines(@"C:\file.txt").Count();

    AR

    ReplyDelete

Post a Comment