abdulrahmanok Posted January 25, 2018 Share Posted January 25, 2018 (edited) Hi brothers, I'm trying to tidy this file : 02-Jan-18 Is : 3 01-Jan-18 Is : 2 03-Jan-18 Is : 1 to make it like this : 01-Jan-18 Is : 2 02-Jan-18 Is : 3 03-Jan-18 Is : 1 I succeed to get list of dates by this code: #include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") dim $Array_TotalHours[1] dim $Array_ToFill[1] For $i = 1 To UBound($aTxt) $Split_File=StringSplit($aTxt[$i],"-Jan");Split Month ;_ArrayDisplay($Split_File) If UBound($Split_File,1)=2 Then ; If not enough array rows Exitloop ExitLoop EndIf ConsoleWrite(@CRLF&$Split_File[1]);Day raw _ArrayAdd($Array_TotalHours, $Split_File[1]) _ArrayAdd($Array_ToFill, $Split_File[1]) Next _ArrayDisplay($Array_ToFill) ;Resault but I can't figure how to make the smaller date comes first solved by: @Earthshine Edited January 26, 2018 by abdulrahmanok Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 sort the array? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 kind of sort, because i want the least dates come first Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 Well have a look at the help file which is what I’m gonna do to see if there’s any date math functions My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 abdulrahmanok 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 1 hour ago, Earthshine said: firstly,thanks for this post it's helped me a lot After using _DateDiff and StringReplace to convert date type this is my try: Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") ;_ArrayDisplay($aTxt) ;$sDate = $aTxt[1] ;$aDate = StringSplit($sDate,"-") Dim $Arraytofill[1] For $i = 1 to UBound($aTxt) $aDate = StringSplit($aTxt[$i],"-") If UBound($aDate,1)=2 Then ; If not enough array rows Exitloop ExitLoop EndIf $Convert = StringReplace($aDate[3],$aDate[3],@YEAR) & "/" & StringReplace($aDate[2],$aDate[2],@MON) & "/" &$aDate[1] $old=$aTxt[$i] _ArrayAdd($Arraytofill,$Convert) ;MsgBox(0,"Old: "&$aTxt[$i], $Convert) Next _ArrayDisplay($Arraytofill) $iDateCalc = _DateDiff( 'D',$Arraytofill[2],$Arraytofill[1]) MsgBox( 4096, "", "Resault " & $iDateCalc ) if $iDateCalc >=1 Then MsgBox(0,"","This line must go down") Else MsgBox(0,"","Keep line") EndIf but still need : 1- some way to compare between all array values . 2- I don't have idea about how to make this founded line go down Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 (edited) that code does not compile. How about the whole thing? I will assist you, but I won't do your work for you. Edited January 25, 2018 by Earthshine abdulrahmanok 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 Whole code: expandcollapse popup#include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") ;_ArrayDisplay($aTxt) ;$sDate = $aTxt[1] ;$aDate = StringSplit($sDate,"-") Dim $Arraytofill[1] For $i = 1 to UBound($aTxt) $aDate = StringSplit($aTxt[$i],"-") If UBound($aDate,1)=2 Then ; If not enough array rows Exitloop ExitLoop EndIf $Convert = StringReplace($aDate[3],$aDate[3],@YEAR) & "/" & StringReplace($aDate[2],$aDate[2],@MON) & "/" &$aDate[1] $old=$aTxt[$i] _ArrayAdd($Arraytofill,$Convert) ;MsgBox(0,"Old: "&$aTxt[$i], $Convert) Next _ArrayDisplay($Arraytofill) $iDateCalc = _DateDiff( 'D',$Arraytofill[2],$Arraytofill[1]) MsgBox( 4096, "", "Resault " & $iDateCalc ) if $iDateCalc >=1 Then MsgBox(0,"","This line must go down") Else MsgBox(0,"","Keep line") EndIf "Test.txt" contains : 02-Jan-18 Is : 3 01-Jan-18 Is : 2 03-Jan-18 Is : 1 Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 Ok. When I get back to my desk I will look at it My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 (edited) try this. added an _ArraySort with default paramters. Read the help file regarding For Loops for how to access all the elements of your array later in your program once built. expandcollapse popup#include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") ;_ArrayDisplay($aTxt) ;$sDate = $aTxt[1] ;$aDate = StringSplit($sDate,"-") Dim $Arraytofill[1] For $i = 1 to UBound($aTxt) $aDate = StringSplit($aTxt[$i],"-") If UBound($aDate,1)=2 Then ; If not enough array rows Exitloop ExitLoop EndIf $Convert = StringReplace($aDate[3],$aDate[3],@YEAR) & "/" & StringReplace($aDate[2],$aDate[2],@MON) & "/" &$aDate[1] $old=$aTxt[$i] _ArrayAdd($Arraytofill,$Convert) ;MsgBox(0,"Old: "&$aTxt[$i], $Convert) Next _ArraySort($Arraytofill) _ArrayDisplay($Arraytofill) $iDateCalc = _DateDiff( 'D',$Arraytofill[2],$Arraytofill[1]) MsgBox( 4096, "", "Resault " & $iDateCalc ) if $iDateCalc >=1 Then MsgBox(0,"","This line must go down") Else MsgBox(0,"","Keep line") EndIf Edited January 25, 2018 by Earthshine abdulrahmanok 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 thanks that's solved how to sort lines ... now I'm trying hard to rewrite file again with new sorted days with it's hours to be like this : 01-Jan-18 Is : 2 02-Jan-18 Is : 3 03-Jan-18 Is : 1 Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 you can format the date strings. look at the date stuff in the help file, and also under the User Defined Functions as well that have been integrated into AutoIT My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 to make it more clear I edited "Test.txt" to be : 02-Jan-18 Is : Value for Jan2 01-Jan-18 Is : Value for Jan1 03-Jan-18 Is : Value for Jan3 and my code : expandcollapse popup#include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") ;_ArrayDisplay($aTxt) ;$sDate = $aTxt[1] ;$aDate = StringSplit($sDate,"-") Dim $Arraytofill[1] For $i = 1 to UBound($aTxt) $aDate = StringSplit($aTxt[$i],"-") If UBound($aDate,1)=2 Then ; If not enough array rows Exitloop ExitLoop EndIf $Convert = StringReplace($aDate[3],$aDate[3],@YEAR) & "/" & StringReplace($aDate[2],$aDate[2],@MON) & "/" &$aDate[1] $old=$aTxt[$i] _ArrayAdd($Arraytofill,$Convert) ;MsgBox(0,"Old: "&$aTxt[$i], $Convert) Next _ArraySort($Arraytofill) _ArrayDelete($Arraytofill, 0) ;Delete Total Rows Value _ArrayDisplay($Arraytofill) $fileToRead = @ScriptDir & "\Test.txt" Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt2 = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$3,");Ready line and pass line $aTxt2 = StringSplit($aTxt2, ",");Ready line and pass line _ArrayDelete($aTxt2, 0) ;Delete Total Rows Value _ArrayDisplay($aTxt2) For $i = 0 to UBound($Arraytofill)-1 FileWrite($fileToRead,@crlf&$Arraytofill[$i]) FileWrite($fileToRead,@crlf&$aTxt2[$i]) Next Result is : 02-Jan-18 Is : Value for Jan2 01-Jan-18 Is : Value for Jan1 03-Jan-18 Is : Value for Jan3 2018/01/01Value for Jan2 2018/01/02Value for Jan1 2018/01/03Value for Jan3 notice that second line is not true it must be like this : 2018/01/01Value for Jan1 2018/01/02Value for Jan2 2018/01/03Value for Jan3 Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 Another try with _LineNumsOfSearchStr expandcollapse popup#include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> dim $foundedNUM $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") _ArrayDelete($aTxt, 0) ;Delete Total Rows Value ;$sDate = $aTxt[1] ;$aDate = StringSplit($sDate,"-") Dim $Arraytofill[1] For $i = 0 to UBound($aTxt) $aDate = StringSplit($aTxt[$i],"-") If UBound($aDate,1)=2 Then ; If not enough array rows Exitloop ExitLoop EndIf $Convert = StringReplace($aDate[3],$aDate[3],@YEAR) & "/" & StringReplace($aDate[2],$aDate[2],@MON) & "/" &$aDate[1] $old=$aTxt[$i] _ArrayAdd($Arraytofill,$Convert) ;MsgBox(0,"Old: "&$aTxt[$i], $Convert) Next _ArraySort($Arraytofill) _ArrayDelete($Arraytofill, 0) ;Delete Total Rows Value $fileToRead = @ScriptDir & "\Test.txt" Local $FileRead = FileRead($fileToRead) & @CRLF $aTxt2 = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$3,");Ready line and pass line $aTxt2 = StringSplit($aTxt2, ",");Ready line and pass line _ArrayDelete($aTxt2, 0) ;Delete Total Rows Value ;_ArrayDisplay($Arraytofill) ;_ArrayDisplay($aTxt2) Dim $final_array[1] For $i = 0 to UBound($aTxt,1)/2-1 ;ConsoleWrite(@CRLF&$aTxt[$i]) $getLine=_LineNumsOfSearchStr($fileToRead,$aTxt[$i]) $Second_Line=FileReadLine($fileToRead,$foundedNUM+1) ;ConsoleWrite(@CRLF&"Next Line is: "&$Second_Line) _ArrayAdd($final_array,$Second_Line) Next _ArrayDelete($final_array, 0) ; _ArrayDisplay($Arraytofill) _ArrayDisplay($final_array) ;~ $iDateCalc = _DateDiff( 'D',$Arraytofill[2],$Arraytofill[1]) ;~ MsgBox( 4096, "", "Resault " & $iDateCalc ) ;~ if $iDateCalc >=1 Then ;~ MsgBox(0,"","This line must go down") ;~ Else ;~ MsgBox(0,"","Keep line") ;~ EndIf For $i = 0 to UBound($Arraytofill)-1 ConsoleWrite(@CRLF&$Arraytofill[$i]) ConsoleWrite(@CRLF&$final_array[$i]) ;FileWrite($fileToRead,@crlf&$Arraytofill[$i]) ;FileWrite($fileToRead,@crlf&$final_array[$i]) Next Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False) Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = "" If FileExists($sFileName) = 0 Then Return 1 Do $sFile = FileRead($sFileName) $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring" If $location > 0 Then $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "\1"), "(?s)(\v+)", 3) ;Find line number $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number $foundedNUM=$iCurrentLineNum ;Consolewrite(@crlf&"Founded Date Line Is: "&$foundedNUM&@crlf) ; _FileWriteToLine($sIniFile, 1, $iCurrentLineNum, True) ;ConsoleWrite("CharPos: " & $location & " Ln: " & $iCurrentLineNum & @CRLF) $sRes &= $iCurrentLineNum & "|" If $bDeleteLine Then Else $iOccur += 1 EndIf Else ExitLoop EndIf Sleep(10) Until 0 FileClose($sFile) ;ShellExecute($sFileName) Return StringSplit(StringTrimRight($sRes, 1), "|") EndFunc ;==>_LineNumsOfSearchStr Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 Ty very much @Earthshine after playing around Finally I did it : expandcollapse popup#include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> dim $foundedNUM $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") _ArrayDelete($aTxt, 0) ;Delete Total Rows Value Dim $Arraytofill[1] For $i = 0 to UBound($aTxt,1) -1 ;$aDate = StringSplit($aTxt[$i],"-") ;~ If UBound($aDate,1)=2 Then ; If not enough array rows Exitloop ;~ ExitLoop ;~ EndIf ;$Convert = StringReplace($aDate[3],$aDate[3],@YEAR) & "/" & StringReplace($aDate[2],$aDate[2],@MON) & "/" &$aDate[1] ;$old=$aTxt[$i] _ArrayAdd($Arraytofill,$aTxt[$i]) ;MsgBox(0,"Old: "&$aTxt[$i], $Convert) Next _ArrayDelete($Arraytofill, 0) ;Delete Total Rows Value _ArraySort($Arraytofill) _ArrayDisplay($Arraytofill,"$Arraytofill") $aTxt2 = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$3,");Ready line and pass line $aTxt2 = StringSplit($aTxt2, ",");Ready line and pass line _ArrayDelete($aTxt2, 0) ;Delete Total Rows Value Dim $final_array[1] For $i = 0 to UBound($Arraytofill,1)-1 ;ConsoleWrite(@CRLF&$aTxt[$i]) $getLine=_LineNumsOfSearchStr($fileToRead,$Arraytofill[$i]) $Second_Line=FileReadLine($fileToRead,$foundedNUM+1) ;ConsoleWrite(@CRLF&"Next Line is: "&$Second_Line) _ArrayAdd($final_array,$Second_Line) Next _ArrayDelete($final_array, 0) ; _ArrayDisplay($final_array) For $i = 0 to UBound($Arraytofill,1)-1 ConsoleWrite(@CRLF&$Arraytofill[$i]) ConsoleWrite(@CRLF&$final_array[$i]) ;FileWrite($fileToRead,@crlf&$Arraytofill[$i]) ;FileWrite($fileToRead,@crlf&$final_array[$i]) Next Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False) Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = "" If FileExists($sFileName) = 0 Then Return 1 Do $sFile = FileRead($sFileName) $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring" If $location > 0 Then $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "\1"), "(?s)(\v+)", 3) ;Find line number $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number $foundedNUM=$iCurrentLineNum ;Consolewrite(@crlf&"Founded Date Line Is: "&$foundedNUM&@crlf) ; _FileWriteToLine($sIniFile, 1, $iCurrentLineNum, True) ;ConsoleWrite("CharPos: " & $location & " Ln: " & $iCurrentLineNum & @CRLF) $sRes &= $iCurrentLineNum & "|" If $bDeleteLine Then Else $iOccur += 1 EndIf Else ExitLoop EndIf Sleep(10) Until 0 FileClose($sFile) ;ShellExecute($sFileName) Return StringSplit(StringTrimRight($sRes, 1), "|") EndFunc ;==>_LineNumsOfSearchStr Result: 01-Jan-18 Is : Value for Jan1 02-Jan-18 Is : Value for Jan2 03-Jan-18 Is : Value for Jan3 Earthshine 1 Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 25, 2018 Author Share Posted January 25, 2018 (edited) There is a little issue , when I put code between "Func" doesn't work correctly : expandcollapse popup_Sort_File() Func _Sort_File() dim $foundedNUM $fileToRead = @ScriptDir & "\Test.txt" ;###################################### Load Days Local $FileRead = FileRead($fileToRead) $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") _ArrayDelete($aTxt, 0) ;Delete Total Rows Value Dim $Arraytofill[1] For $i = 0 to UBound($aTxt,1) -1 _ArrayAdd($Arraytofill,$aTxt[$i]) Next _ArrayDelete($Arraytofill, 0) ;Delete Total Rows Value _ArraySort($Arraytofill) _ArrayDisplay($Arraytofill,"$Arraytofill") $aTxt2 = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$3,");Ready line and pass line $aTxt2 = StringSplit($aTxt2, ",");Ready line and pass line _ArrayDelete($aTxt2, 0) ;Delete Total Rows Value Dim $final_array[1] For $i = 0 to UBound($Arraytofill,1)-1 $fileToRead = @ScriptDir & "\Test.txt" ConsoleWrite(@CRLF&$aTxt[$i]) $getLine=_LineNumsOfSearchStr($fileToRead,$Arraytofill[$i]) $Second_Line=FileReadLine($fileToRead,$foundedNUM+1) ;ConsoleWrite(@CRLF&"Next Line is: "&$Second_Line) _ArrayAdd($final_array,$Second_Line) Next _ArrayDelete($final_array, 0) ; _ArrayDisplay($final_array,"$final_array") For $i = 0 to UBound($Arraytofill,1)-1 ConsoleWrite(@CRLF&$Arraytofill[$i]) ConsoleWrite(@CRLF&$final_array[$i]) ;FileWrite($fileToRead,@crlf&$Arraytofill[$i]) ;FileWrite($fileToRead,@crlf&$final_array[$i]) Next EndFunc Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False) Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = "" If FileExists($sFileName) = 0 Then Return 1 Do $sFile = FileRead($sFileName) $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring" If $location > 0 Then $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "\1"), "(?s)(\v+)", 3) ;Find line number $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number $foundedNUM=$iCurrentLineNum ;Consolewrite(@crlf&"Founded Date Line Is: "&$foundedNUM&@crlf) ; _FileWriteToLine($sIniFile, 1, $iCurrentLineNum, True) ;ConsoleWrite("CharPos: " & $location & " Ln: " & $iCurrentLineNum & @CRLF) $sRes &= $iCurrentLineNum & "|" If $bDeleteLine Then Else $iOccur += 1 EndIf Else ExitLoop EndIf Sleep(10) Until 0 FileClose($sFile) ;ShellExecute($sFileName) Return StringSplit(StringTrimRight($sRes, 1), "|") EndFunc ;==>_LineNumsOfSearchStr after remove (Func _Sort_File) every thing back to normal ! Edited January 25, 2018 by abdulrahmanok Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 I knew you could do it 😀 abdulrahmanok 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted January 25, 2018 Share Posted January 25, 2018 (edited) I’ll chech it tomorrow Edited January 25, 2018 by Earthshine abdulrahmanok 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abdulrahmanok Posted January 26, 2018 Author Share Posted January 26, 2018 (edited) 20 hours ago, abdulrahmanok said: There is a little issue , when I put code between "Func" doesn't work correctly : Finally I solved this also by add : Return $foundedNUM and make "$foundedNUM" Global Global $foundedNUM=$iCurrentLineNum Final code : expandcollapse popup#include<array.au3> ;#include '_Startup.au3' #include <Date.au3> #include<File.au3> Sort_File() Func Sort_File() $fileToRead = @ScriptDir & "\daysarray.qu" ;dim $foundedNUM ;###################################### Load Days Local $FileRead = FileRead($fileToRead) $aTxt = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$1,");Read first line to array $aTxt = StringSplit($aTxt, ",") _ArrayDelete($aTxt, 0) ;Delete Total Rows Value Dim $Arraytofill[1] For $i = 0 to UBound($aTxt,1) -1 _ArrayAdd($Arraytofill,$aTxt[$i]) Next _ArrayDelete($Arraytofill, 0) ;Delete Total Rows Value _ArraySort($Arraytofill) _ArrayDisplay($Arraytofill,"$Arraytofill") $aTxt2 = StringRegExpReplace($FileRead & @CRLF, "(.*?)(\r\n)(.*?)(\r\n)", "$3,");Ready line and pass line $aTxt2 = StringSplit($aTxt2, ",");Ready line and pass line _ArrayDelete($aTxt2, 0) ;Delete Total Rows Value Dim $final_array[1] For $i = 0 to UBound($Arraytofill,1)-1 ;$fileToRead = @ScriptDir & "\daysarray.qu" ConsoleWrite(@CRLF&$aTxt[$i]) $getLine=_LineNumsOfSearchStr($fileToRead,$Arraytofill[$i]) ;ConsoleWrite(@CRLF&"Next Line is: "&$Second_Line) $Second_Line=FileReadLine($fileToRead,$foundedNUM+1) _ArrayAdd($final_array,$Second_Line) Next _ArrayDelete($final_array, 0) ; _ArrayDisplay($final_array,"$final_array") FileDelete($fileToRead) Sleep(1000) For $i = 1 to UBound($Arraytofill,1)-1 ConsoleWrite(@CRLF&$Arraytofill[$i]) ConsoleWrite(@CRLF&$final_array[$i]) ;_ArrayDisplay($final_array,"$final_array") FileWrite($fileToRead,@crlf&$Arraytofill[$i]) FileWrite($fileToRead,@crlf&$final_array[$i]) Next TidyDayssarray() EndFunc Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False) Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = "" If FileExists($sFileName) = 0 Then Return 1 Do $sFile = FileRead($sFileName) $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring" If $location > 0 Then $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "\1"), "(?s)(\v+)", 3) ;Find line number $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number Global $foundedNUM=$iCurrentLineNum ;Consolewrite(@crlf&"Founded Date Line Is: "&$foundedNUM&@crlf) ; _FileWriteToLine($sIniFile, 1, $iCurrentLineNum, True) ;ConsoleWrite("CharPos: " & $location & " Ln: " & $iCurrentLineNum & @CRLF) $sRes &= $iCurrentLineNum & "|" If $bDeleteLine Then Else $iOccur += 1 EndIf Else ExitLoop EndIf Sleep(10) Until 0 FileClose($sFile) ;ShellExecute($fileToRead) Return StringSplit(StringTrimRight($sRes, 1), "|") Return $foundedNUM EndFunc ;==>_LineNumsOfSearchStr Func TidyDayssarray() Global $aLines _FileReadToArray($fileToRead, $aLines) For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray($fileToRead, $aLines, 1) ConsoleWrite(@crlf& " Tidy Done" & @CRLF) EndFunc Edited January 26, 2018 by abdulrahmanok Earthshine 1 Link to comment Share on other sites More sharing options...
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