AutoHotkey Community

It is currently May 26th, 2012, 2:10 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Looping Effect Help
PostPosted: January 14th, 2009, 4:22 pm 
Offline
User avatar

Joined: August 4th, 2008, 1:22 pm
Posts: 241
Location: UK
Hey i got similar thing lookin like this:

Code:
/*
up.txt contains:

Line1: 574366262
Line2: 789645645
Line3: 659786532
*/

FileReadLine, 1, up.txt, 1
FileReadLine, 2, up.txt, 2
FileReadLine, 3, up.txt, 3

O1 = %1%
O1 := RegExReplace(O1, "\d(?=(\d{3})+(\D|$))", "$0,")

O2 = %2%
O2 := RegExReplace(O2, "\d(?=(\d{3})+(\D|$))", "$0,")

O3 = %3%
O3 := RegExReplace(O3, "\d(?=(\d{3})+(\D|$))", "$0,")



I was wondering, if there is a looping effect i can add after the "FileReadLine, 3, up.txt, 3"

coz in this script i have like 250 of these regexreplace things and it makes the script increadibly long for no reason...

i also have about 70 file read lines.. all in one file... and the output for each filereadline command is the same as the line number

so its like

FileReadLine, 1, somefile.txt, 1
FileReadLine, 2, somefile.txt, 2

can i loop this aswell?

Thanks for those who read/help

D4BST3R


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 5:29 pm 
Offline

Joined: February 17th, 2008, 8:52 pm
Posts: 314
I am not a guru at file reading or regex so this a newbie attempt at doing the loop. Not tested but hopefully it starts you in the right direction.

Code:
Loop 70 {
   FileReadLine, Line%A_Index%, up.txt, %A_Index%
   Line%A_Index% := RegExReplace(Line%A_Index%, "\d(?=(\d{3})+(\D|$))", "$0,")

}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 6:31 pm 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Might I recommend using better variable names... Numbers SHOULD be reserved for command-line arguments and then loaded from there to a "normal" variable. It's just hard reading code and not knowing what's a number and what's a variable (sorry, can't remember the syntax for all the commands).

Next, if you have like 70 FileReadLines, it makes me wonder are you reading the entire file (or most of it)? If so, FileRead might be a better choice. See the remarks section.

Update1:

Just a small modification. By making the digit selection possessive, you don't have to back trace (not sure if it helps at all, but it's "logical")
Also, added the "S" (study) RegEx option - let the parser optimize the RegEx if it can.

Code:
#SingleInstance Force
#NoEnv

FileRead, InputFile, up.txt

LineParse_RegEx := "S)\d(?=(\d{3})++(\D|$))"

Loop, Parse, InputFile, `n, %A_Space%%A_Tab%
{
    Line := A_LoopField
    Line%A_Index% := RegExReplace(Line, LineParse_RegEx, "$0,")
   
    MsgBox, % Line%A_Index%
}


Edit:

Cool regex by the way, still can't make sense of it even though I know what it does - it makes my head hurt :shock:

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, G. Sperotto, LazyMan, poserpro, stanman, Tilter_of_Windmills and 8 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group