#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    9
    Rep Power
    0

    Reading random line


    Hey guys, how do you go about reading a random line (of text) from a file using arrays?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    9
    Rep Power
    0
    Thanks buddy!

IMN logo majestic logo threadwatch logo seochat tools logo