Belfigor Posted October 12, 2008 Posted October 12, 2008 (edited) Hi. For example i have file named "test" It contains 1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48) 2. Action II (8 hours, 39 minutes, 54 seconds; Finish: 12.10.2008 17:26:42) 3. Action III (1 hour, 35 minutes, 41 seconds; Finish: 12.10.2008 19:02:24) 4. Action IV (4 days, 1 hour, 27 minutes, 1 second; Finish: 16.10.2008 20:29:25) When i am using _FileReadToArray("test.txt", $ActionArray) i am reciaving an array, that have string "1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48)" in $ActionArray[1] How can i delete every information that i don need, and recive from "1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48)", string like "Action I - 12.10.2008 8:46:48"? Help please Edited October 12, 2008 by Belfigor [size="1"]My bear is so cute asleep in the closet, not even drinking vodka. My nuclear bomb name is Natasha.[/size]
rasim Posted October 12, 2008 Posted October 12, 2008 (edited) Hi. For example i have file named "test" It contains 1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48) 2. Action II (8 hours, 39 minutes, 54 seconds; Finish: 12.10.2008 17:26:42) 3. Action III (1 hour, 35 minutes, 41 seconds; Finish: 12.10.2008 19:02:24) 4. Action IV (4 days, 1 hour, 27 minutes, 1 second; Finish: 16.10.2008 20:29:25) When i am using _FileReadToArray("test.txt", $ActionArray) i am reciaving an array, that have string "1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48)" in $ActionArray[1] How can i delete every information that i don need, and recive from "1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48)", string like "Action I - 12.10.2008 8:46:48"? Help please Try this: $sFile = @ScriptDir & "\test.txt" $sRead = FileRead($sFile) $sRead = StringRegExpReplace($sRead, "(?i).*(Action\s?\w+).*?:(.*)\)", "\1 -\2") $hFile = FileOpen($sFile, 2) FileWrite($hFile, $sRead) FileClose($hFile) Edited October 12, 2008 by rasim
herewasplato Posted October 12, 2008 Posted October 12, 2008 ...or the hard wayDim $ActionArray[2] $ActionArray[1] = "1. Action I (1 hour, 51 minutes, 38 seconds; Finish: 12.10.2008 8:46:48)" $act = StringInStr($ActionArray[1], "Action") $par1 = StringInStr($ActionArray[1], "(") $part1 = StringMid($ActionArray[1], $act, $par1 - $act) $fin = StringInStr($ActionArray[1], "Finish") $par2 = StringInStr($ActionArray[1], ")") $part2 = StringMid($ActionArray[1], $fin, $par2 - $fin) MsgBox(0, "", $part1 & "- " & $part2):-) [size="1"][font="Arial"].[u].[/u][/font][/size]
Belfigor Posted October 12, 2008 Author Posted October 12, 2008 (edited) Thank you every one! herewasplato's way is more understandeble for me thank you Now i have script that will generate for me from the test.txt file test2.txt file with lines looks like that: [name] [date] [science I] [13.12.2008 4:17:47] [Engineering IV] [13.12.2008 4:57:39] [industry II] [13.12.2008 8:03:22] [industry III] [14.12.2008 8:03:22] [industry IV] [15.12.2008 8:03:22] [industry V] [16.12.2008 8:03:22] now i need to change .txt file once more. How can i teach my script to understand how to mark each line if that line have special word? For example, if script found in any line, words: "Science I" "Science II" "Science III" "Science IV" "Science V", he will add to the begining of the line word "Science" and after all changes line [science I] [13.12.2008 4:17:47] will looks like [class] [name] [date] [science] [science I] [13.12.2008 4:17:47] How can i do it? Edited October 12, 2008 by Belfigor [size="1"]My bear is so cute asleep in the closet, not even drinking vodka. My nuclear bomb name is Natasha.[/size]
Belfigor Posted October 12, 2008 Author Posted October 12, 2008 Allready found how to make it. Thx everyone [size="1"]My bear is so cute asleep in the closet, not even drinking vodka. My nuclear bomb name is Natasha.[/size]
oMBRa Posted October 12, 2008 Posted October 12, 2008 Try this: $sFile = @ScriptDir & "\test.txt" $sRead = FileRead($sFile) $sRead = StringRegExpReplace($sRead, "(?i).*(Action\s?\w+).*?:(.*)\)", "\1 -\2") $hFile = FileOpen($sFile, 2) FileWrite($hFile, $sRead) FileClose($hFile) can u explain that "+" ?... why it is needed?
MrCreatoR Posted October 12, 2008 Posted October 12, 2008 can u explain that "+"Help file can explain things to + Repeat the previous character, set or group 1 or more times. Equivalent to {1,} Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
oMBRa Posted October 14, 2008 Posted October 14, 2008 I asked here because I didnt understand reading the help
herewasplato Posted October 14, 2008 Posted October 14, 2008 I asked here because I didnt understand reading the helpI agree.It does not make sense to me either - but I've not spent a lot of time going over and over it. When I find a task that I must use RegExp in, I'll probably dive in. Until then, the stuff I posted works for me. [size="1"][font="Arial"].[u].[/u][/font][/size]
Moderators SmOke_N Posted October 14, 2008 Moderators Posted October 14, 2008 The "+" is telling the regex engine that there are at least 1 word character but may be more... to get through all of them before it continues to the next match command. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
MrCreatoR Posted October 15, 2008 Posted October 15, 2008 Here is simple example that shows why to use "+": $Var = "My 1001 String" $Ret1 = StringRegExpReplace($Var, ".*[^\d](\d).*", "\1") $Ret2 = StringRegExpReplace($Var, ".*[^\d](\d+).*", "\1") MsgBox(0, "", StringFormat("Without '+'\t= %i\nWith '+'\t\t= %i", $Ret1, $Ret2)) Here we can see that when we use "+" with "\d" (it's digits matching), the RegExp match number that include more than 1 digit. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
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