Jump to content

Get text from random line to the last line ?


MrVietA2
 Share

Recommended Posts

Hi !

I would like to get text from the random line to the last line of a text file. My example of text file here :) :

Hello
My name is Viet
I'm a student

I love autoit

In this example, I would like to get text from the line 2 to the last line (line 5), so it's like this :

My name is Viet
I'm a student

I love autoit

Could you tell me how can I do it ?

Thanks so much !

Edited by MrVietA2
Link to comment
Share on other sites

Easy, look here:

#Include <File.au3>
Global $text
Global $result = ""
_FileReadToArray("your file here", $text)
$RandomLine = Random(1, $text[0], 1)
For $i = $RandomLine To $text[0]
 $result &= $text[$i]
Next
MsgBox(0, "result", $result)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

he did.

You call that an example?

Now this is an example.

#include <File.au3>
Global $aArray
Global $sResult = ""
_FileReadToArray("MrVietA2File.txt", $aArray)
$RandomLine = Random(2, $aArray[0], 1) ; Starting random line somewhere between line 2 and last line of text file.
$sResult = "Starting at line number " & $RandomLine & ". :-" & @LF & @LF
For $i = $RandomLine To $aArray[0]
    $sResult &= $aArray[$i] & @LF
Next
MsgBox(0, "result", $sResult)
Link to comment
Share on other sites

You call that an example?

Now this is an example.

#include <File.au3>
Global $aArray
Global $sResult = ""
_FileReadToArray("MrVietA2File.txt", $aArray)
$RandomLine = Random(2, $aArray[0], 1) ; Starting random line somewhere between line 2 and last line of text file.
$sResult = "Starting at line number " & $RandomLine & ". :-" & @LF & @LF
For $i = $RandomLine To $aArray[0]
    $sResult &= $aArray[$i] & @LF
Next
MsgBox(0, "result", $sResult)

No .. that's spoon-feeding someone code. Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

@Blue_Drache

Thanks, you understood perfectly what I was trying to do.

I have seen his post where he was asking for an example and I decided to not answer and to give him a chance to understand what I did there. Unfortunately for him, somebody else took the nanny role.

I can see that my "example" was good enough for Malkey ;) because he only changed it just a little bit :)

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

@Blue_Drache

Thanks, you understood perfectly what I was trying to do.

I have seen his post where he was asking for an example and I decided to not answer and to give him a chance to understand what I did there. Unfortunately for him, somebody else took the nanny role.

I can see that my "example" was good enough for Malkey ;) because he only changed it just a little bit :)

If you give a man a fire, he's warm for a day.

If you set a man on fire, he's warm for the rest of his life.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

@Blue_Drache

Thanks, you understood perfectly what I was trying to do.

I have seen his post where he was asking for an example and I decided to not answer and to give him a chance to understand what I did there. Unfortunately for him, somebody else took the nanny role.

I can see that my "example" was good enough for Malkey ;) because he only changed it just a little bit :)

@enaiman

Sorry, I thought I was helping you by correcting the silly mistakes in your cleverly disguised spoon-feeding example.

I hope your "Teaching by Bad Example" method does not catch on.

nanny Malkey.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...