|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading random line
Hey guys, how do you go about reading a random line (of text) from a file using arrays?
|
|
#2
|
||||
|
||||
|
Code:
var
stlList : TStringList;
index : integer;
ret : string;
begin
Result := '';
try
Randomize;
stlList := TStringList.Create;
stlList.LoadFromFile('file.txt');
index := random(stlList.Count - 1);
Result := stlList.strings[index];
finally
stlList.Free;
end;
end;
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
|||
|
|||
|
Thanks buddy!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Reading random line |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|