LoneWolf_2106 Posted June 23, 2017 Posted June 23, 2017 Hi everybody, i have a question related to strings items in an Array and sorting. Maybe someone can advice me how to solve the issue. I have an Array of strings, every item of the Array is as following: INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection] INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x I want to sort the item in the array by date and time, is there any function which allows me to sort by date/time? Thanks in advance
Moderators JLogan3o13 Posted June 23, 2017 Moderators Posted June 23, 2017 Moved to appropriate forum "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Subz Posted June 23, 2017 Posted June 23, 2017 Basic example, although someone that is good with RegEx could write something better. #include <Array.au3> Local $aInfo[2] = ['INFO [07.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]', 'INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x'] Local $aModified[UBound($aInfo)][2], $sDate For $i = 0 To UBound($aInfo) - 1 $sDate = StringMid($aInfo[$i], StringInStr($aInfo[$i], "INFO [") + StringLen("INFO ["), 19) $aModified[$i][0] = StringFormat("%04i/%02i/%02i", StringMid($sDate, 7, 4), StringMid($sDate, 4, 2), StringLeft($sDate, 2)) & StringRight($sDate, 9) $aModified[$i][1] = $aInfo[$i] Next _ArraySort($aModified, 0, 0, 0, 0) _ArrayDisplay($aModified)
Danyfirex Posted June 23, 2017 Posted June 23, 2017 (edited) another way. #include <Array.au3> Local $aArray = ["INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]", _ "INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x", _ "INFO [07.06.2017 12:55:11] [main] Dummy String1", _ "INFO [07.06.2016 09:55:11] [main] Dummy String2", _ "INFO [07.06.2017 09:55:12] [main] Dummy String3", _ "INFO [07.06.2017 09:55:11] [main] Dummy String4"] _ArrayDisplay($aArray, "No sorted") _Sort($aArray) _ArrayDisplay($aArray, "Sorted") Func _Sort(ByRef $aArray) For $i = UBound($aArray) - 1 To 1 Step -1 For $j = 1 To $i If _GetNumber($aArray[$j - 1]) > _GetNumber($aArray[$j]) Then $temp = $aArray[$j - 1] $aArray[$j - 1] = $aArray[$j] $aArray[$j] = $temp EndIf Next Next Return $aArray EndFunc ;==>_Sort Func _GetNumber($String) Return Number(StringRegExpReplace(StringMid($String, 7, 19), '(\d{2})\.(\d{2})\.(\d{4})', "$3$2$1")) ;mikell's regexp EndFunc ;==>_GetNumber Saludos Edited June 26, 2017 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
iamtheky Posted June 23, 2017 Posted June 23, 2017 So assuming you have that portion of the string, since that's been done twice now, here is a way with datediff #include <Date.au3> #include<array.au3> local $Arr[5] $Arr[0] = "13.06.2017 11:48:01" $Arr[1] = "07.06.2017 08:55:44" $Arr[2] = "05.06.2017 08:55:40" $Arr[3] = "12.06.2017 08:55:43" $Arr[4] = "07.06.2017 08:55:42" For $i = 0 to ubound($Arr) - 2 If stringleft( _DateDiff("s" , stringmid($Arr[$i] , 7 , 4) & "/" & stringmid($Arr[$i] , 4 , 2) & "/" & stringmid($Arr[$i] , 1 , 2) & " " & stringright($Arr[$i] , 8) , stringmid($Arr[$i + 1] , 7 , 4) & "/" & stringmid($Arr[$i + 1] , 4 , 2) & "/" & stringmid($Arr[$i + 1] , 1 , 2) & " " & stringright($Arr[$i + 1] , 8)) , 1) = "-" Then _ArraySwap($Arr , $i , $i + 1) $i = -1 EndIf Next _ArrayDisplay($Arr) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted June 23, 2017 Posted June 23, 2017 And another way ... sooo classic #include <Array.au3> Local $aArray[6] = ["INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]", _ "INFO [07.06.2018 08:55:44] [main] MDU5 - Ver 5.1x", _ "INFO [07.06.2017 12:55:11] [main] Dummy String1", _ "INFO [07.06.2016 09:55:11] [main] Dummy String2", _ "INFO [07.06.2017 09:55:12] [main] Dummy String3", _ "INFO [07.06.2017 09:55:11] [main] Dummy String4"] _ArrayDisplay($aArray, "No sorted") _Sort($aArray) _ArrayDisplay($aArray, "Sorted") Func _Sort(ByRef $aArray) _ArrayColInsert($aArray, 1) For $i = 0 To UBound($aArray) - 1 $aArray[$i][1] = StringRegExpReplace($aArray[$i][0], '(\d{2})\.(\d{2})\.(\d{4})', "$3$2$1") Next _ArraySort($aArray, 0, 0, 0, 1) _ArrayColDelete($aArray, 1) EndFunc ;==>_Sort Gianni and dmob 2
LoneWolf_2106 Posted June 26, 2017 Author Posted June 26, 2017 This solution worked greatly. Many thanks. I didn't try yet the other solutions On 23.06.2017 at 6:39 PM, Danyfirex said: another way. #include <Array.au3> Local $aArray = ["INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]", _ "INFO [07.06.2017 08:55:44] [main] MDU5 - Ver 5.1x", _ "INFO [07.06.2017 12:55:11] [main] Dummy String1", _ "INFO [07.06.2016 09:55:11] [main] Dummy String2", _ "INFO [07.06.2017 09:55:12] [main] Dummy String3", _ "INFO [07.06.2017 09:55:11] [main] Dummy String4"] _ArrayDisplay($aArray, "No sorted") _Sort($aArray) _ArrayDisplay($aArray, "Sorted") Func _Sort(ByRef $aArray) For $i = UBound($aArray) - 1 To 1 Step -1 For $j = 1 To $i If _GetNumber($aArray[$j - 1]) > _GetNumber($aArray[$j]) Then $temp = $aArray[$j - 1] $aArray[$j - 1] = $aArray[$j] $aArray[$j] = $temp EndIf Next Next Return $aArray EndFunc ;==>_Sort Func _GetNumber($String) Return Number(StringRegExpReplace(StringMid($String, 7, 19), "\D", "")) EndFunc ;==>_GetNumber Saludos
mikell Posted June 26, 2017 Posted June 26, 2017 LoneWolf_2106, Danyfirex' code fails when tried with the array that I used in my script Danyfirex 1
Danyfirex Posted June 26, 2017 Posted June 26, 2017 (edited) thank you mikell :-P Fixed first reply. Saludos Edited June 26, 2017 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Danyfirex Posted June 26, 2017 Posted June 26, 2017 lol. thank you again. I'll fix it later. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
LoneWolf_2106 Posted June 27, 2017 Author Posted June 27, 2017 (edited) Hi everybody, yes, i have tried with a more complex file and i confirm that it is not working. Sorry Edited June 27, 2017 by LoneWolf_2106
LoneWolf_2106 Posted June 27, 2017 Author Posted June 27, 2017 1 hour ago, Subz said: Can you post the more complex file? Unfortunately i cannot post my original file, because it contains many entries with sensitive data. Anyway there are several entries like the one i posted before. The log content is just bigger. As for now i am using this solution and i will test it for a while: On 23.06.2017 at 9:49 PM, mikell said: And another way ... sooo classic #include <Array.au3> Local $aArray[6] = ["INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]", _ "INFO [07.06.2018 08:55:44] [main] MDU5 - Ver 5.1x", _ "INFO [07.06.2017 12:55:11] [main] Dummy String1", _ "INFO [07.06.2016 09:55:11] [main] Dummy String2", _ "INFO [07.06.2017 09:55:12] [main] Dummy String3", _ "INFO [07.06.2017 09:55:11] [main] Dummy String4"] _ArrayDisplay($aArray, "No sorted") _Sort($aArray) _ArrayDisplay($aArray, "Sorted") Func _Sort(ByRef $aArray) _ArrayColInsert($aArray, 1) For $i = 0 To UBound($aArray) - 1 $aArray[$i][1] = StringRegExpReplace($aArray[$i][0], '(\d{2})\.(\d{2})\.(\d{4})', "$3$2$1") Next _ArraySort($aArray, 0, 0, 0, 1) _ArrayColDelete($aArray, 1) EndFunc ;==>_Sort I have just a problem, i have a monodimensional Array in Input and it is basically "converted" to bidimensional. How can i use the array? I mean, how can i access the array items?
Subz Posted June 27, 2017 Posted June 27, 2017 Basic example: #include <Array.au3> Global $aOneDimension[3] = [2, "Row1", "Row2"] _ArrayDisplay($aOneDimension) For $i = 1 To $aOneDimension[0] MsgBox(4096, "One Dimension Array", $aOneDimension[$i]) Next Global $aTwoDimension[3][3] = [["Row0 Col0", "Row0 Col1", "Row0 Col2"],["Row1 Col0", "Row1 Col1", "Row1 Col2"], ["Row2 Col0", "Row2 Col1", "Row2 Col2"]] _ArrayDisplay($aTwoDimension) For $i = 0 To UBound($aTwoDimension) - 1 MsgBox(4096, "Two Dimension Array", "Row" & $i & @CRLF & $aTwoDimension[$i][0] & @TAB & $aTwoDimension[$i][1] & @TAB & $aTwoDimension[$i][2]) Next
Danyfirex Posted June 27, 2017 Posted June 27, 2017 Hello. Here is my script fixed. #include <Array.au3> Local $aArray[6] = ["INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]", _ "INFO [07.06.2018 08:55:44] [main] MDU5 - Ver 5.1x", _ "INFO [07.06.2017 12:55:11] [main] Dummy String1", _ "INFO [07.06.2016 09:55:11] [main] Dummy String2", _ "INFO [07.06.2017 09:55:12] [main] Dummy String3", _ "INFO [07.06.2017 09:55:11] [main] Dummy String4"] _ArrayDisplay($aArray, "No sorted") _Sort($aArray) _ArrayDisplay($aArray, "Sorted") Func _Sort(ByRef $aArray) For $i = UBound($aArray) - 1 To 1 Step -1 For $j = 1 To $i If _GetNumber($aArray[$j - 1]) > _GetNumber($aArray[$j]) Then $temp = $aArray[$j - 1] $aArray[$j - 1] = $aArray[$j] $aArray[$j] = $temp EndIf Next Next Return $aArray EndFunc ;==>_Sort Func _GetNumber($String) Local $iNumber=Number(StringRegExpReplace(StringRegExpReplace(StringMid($String, 7, 19), '(\d{2})\.(\d{2})\.(\d{4})', "$3$2$1"),"\D","")) ;mikell's regexp plus something Return $iNumber EndFunc ;==>_GetNumber Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
iamtheky Posted June 27, 2017 Posted June 27, 2017 #include <Array.au3> #include <Date.au3> Local $aArray[6] = ["INFO [13.06.2017 11:48:01] [Thread-13] [ConGenImpUsb -> waitForConnection]", _ "INFO [07.06.2018 08:55:44] [main] MDU5 - Ver 5.1x", _ "INFO [07.06.2017 12:55:11] [main] Dummy String1", _ "INFO [07.06.2016 09:55:11] [main] Dummy String2", _ "INFO [07.06.2017 09:55:12] [main] Dummy String3", _ "INFO [07.06.2017 09:55:11] [main] Dummy String4"] For $i = 0 to ubound($aArray) - 2 If stringleft( _DateDiff("s" , stringmid(StringRegExp($aArray[$i] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 7 , 4) & _ "/" & stringmid(StringRegExp($aArray[$i] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 4 , 2) & _ "/" & stringmid(StringRegExp($aArray[$i] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 1 , 2) & _ " " & stringright(StringRegExp($aArray[$i] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 8) , stringmid(StringRegExp($aArray[$i + 1] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 7 , 4) & _ "/" & stringmid(StringRegExp($aArray[$i + 1] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 4 , 2) & _ "/" & stringmid(StringRegExp($aArray[$i + 1] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 1 , 2) & " " & stringright(StringRegExp($aArray[$i+1] , '(\d{2}\.\d{2}\.\d{4}.\d{2}:\d{2}:\d{2})' , 3)[0] , 8)) , 1) = "-" Then _ArraySwap($aArray , $i , $i + 1) $i = -1 EndIf Next _ArrayDisplay($aArray) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
LoneWolf_2106 Posted June 28, 2017 Author Posted June 28, 2017 I have just written so: For $i = 0 To UBound($searchResultArray) - 1 FileWriteLine($hFileOpen, $searchResultArray[$i][0] & @CRLF) Next It looks working
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