Advertisement
ASP_Volume2 VB function enhancement #42975

Quickly retrieve the lines from a text file

This function quickly retrieves a range of lines from a text file.

AI

AI சுருக்கம்: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

மூலக் குறியீடு
original-source
<hr>
<b>Quickly retrieve the lines from a text file</b><br><br>
If you need a quick function to get a line from a text file, try this one. It's very simple to use, for example:<br><br>
Writeln('The 2nd line in c:\autoexec.bat is '+GetLinesFromFile('c:\autoexec.bat',2,2)[0]);
<br><br>
<b>function  GetLinesFromFile(filename:string; linestart, lineend:integer) : TStringList;</b><br>
(*<br>
// Name   : GetLinesFromFile<br>
// Purpose : Returns a series of lines from a text file, starting at linestart and going to lineend<br>
// Date   : 12 Feb 2001<br>
// Comments :<br>
*)<br>
var<br>
&nbsp;&nbsp;fn : textfile;<br>
&nbsp;&nbsp;c : word;<br>
&nbsp;&nbsp;Line : String;<br>
begin<br>
&nbsp;&nbsp;Result:=TStringList.Create;<br>
&nbsp;&nbsp;AssignFile(fn,filename);<br>
&nbsp;&nbsp;Reset(fn);<br>
&nbsp;&nbsp;for c:=0 to LineStart do<br>
&nbsp;&nbsp;&nbsp;&nbsp;ReadLn(fn,Line);<br>
&nbsp;&nbsp;for c:=LineStart to LineEnd do<br>
&nbsp;&nbsp;begin<br>
&nbsp;&nbsp;&nbsp;&nbsp;Result.Add(Line);<br>
&nbsp;&nbsp;&nbsp;&nbsp;ReadLn(fn,Line);<br>
&nbsp;&nbsp;end;<br>
&nbsp;&nbsp;CloseFile(fn);<br>
end;<br>
<br>
Please vote for this code!
அசல் கருத்துகள் (3)
வேபேக் மெஷினிலிருந்து (Wayback Machine) மீட்டெடுக்கப்பட்டது