 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Cephei1
Joined: 04 Aug 2008 Posts: 199 Location: UK
|
Posted: Wed Jan 14, 2009 3:22 pm Post subject: Looping Effect Help |
|
|
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 |
|
| Back to top |
|
 |
vahju
Joined: 17 Feb 2008 Posts: 296
|
Posted: Wed Jan 14, 2009 4:29 pm Post subject: |
|
|
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,")
}
|
|
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Wed Jan 14, 2009 5:31 pm Post subject: |
|
|
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  _________________ 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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|