kickitship Posted June 30, 2010 Posted June 30, 2010 the question is how do i read a random line of text from a file? should be easy enough to do, thanks in advance
matthieuvb Posted June 30, 2010 Posted June 30, 2010 Try this: Global $File $Read = FileRead($File) $Lines = StringSplit(StringReplace($Read, @CRLF, "|"), "|") $Random = Int(Random(1, $Lines[0])) Msgbox(0, "File", $Lines[$Random]) [font=Helvetica, Arial, sans-serif][background=rgb(252, 252, 250)][/background][/font]
notsure Posted June 30, 2010 Posted June 30, 2010 (edited) #Include <File.au3> global $Count = _FileCountLines(@scriptdir & "\yourfile.name") global $file = FileOpen(@scriptdir & "\yourfile.name") global $line = FileReadLine($file, int(random(1, $count))) msgbox(64,"Line", $line) Edited June 30, 2010 by notsure
electrico Posted June 30, 2010 Posted June 30, 2010 (edited) Open file with notepad++. See how much lines it contains. For example, there is 888 lines. Then $handle = FileOpen("C:\example.txt") $info = FileReadLine($handle, Random(1,888,1)) MsgBox (0, "Random line:", $info) Edited June 30, 2010 by electrico
Spiff59 Posted June 30, 2010 Posted June 30, 2010 And just to confuse you, another route... #include <File.au3> Global $aLines _FileReadToArray(@ScriptDir & "\test.txt", $aLines) $Line = $aLines[Random(1, $aLines[0])] MsgBox(1,"", $Line)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now