Sign in to follow this  
Followers 0
MrVietA2

Get text from random line to the last line ?

17 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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)
1 person likes this

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 :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi enaiman ! Thanks for your example

But I would like to get the text from the line 2 (or line 3 or line 4) to the last line (with all random text file). If a text file have 10 lines or 20 lines or 30 lines so what should I do :) ?

Edited by MrVietA2

Share this post


Link to post
Share on other sites

Just alter "Random" expression to get the results you want.

1 person likes this

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 :)

Share this post


Link to post
Share on other sites

Could you give me an example enaiman ? Thank you !

Share this post


Link to post
Share on other sites

he did.

1 person likes this

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

Share this post


Link to post
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)
1 person likes this

Share this post


Link to post
Share on other sites

Perfect example, thanks Malkey !

I can run my program automatic when windows start but can't run when have Internet connected. I have a question and would like to ask you :) : " How could I run my program when have internet connect ?"

Thanks,

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Waiting for Internet:

While Not Ping("google.de")

WEnd

1 person likes this

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Waiting for Internet:

While Not Ping("google.de")

WEnd

So could you tell me how can I check Internet connection and run my program after that :)?

Share this post


Link to post
Share on other sites

Thanks forumer100

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

@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
1 person likes this

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 :)

Share this post


Link to post
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.

1 person likes this

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

@Malkey

I fail to see what are my "silly mistakes" but ... whatever floats your boat.

The OP got his answer and there is absolutely no point in further discussions.


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 :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0