Jump to content

Malkey

MVPs
  • Posts

    2,005
  • Joined

  • Last visited

  • Days Won

    8

Malkey last won the day on July 15 2019

Malkey had the most liked content!

About Malkey

Profile Information

  • Member Title

Recent Profile Visitors

1,203 profile views

Malkey's Achievements

  1. Try this. #include <Debug.au3> _Main() Func _Main() Local $sgData $sgData &= " aaa := bbb OR" & @CRLF $sgData &= " ccc;" & @CRLF $sgData &= " ddd := eee OR" & @CRLF $sgData &= " fff;" & @CRLF $sgData &= " ggg := hhh OR" & @CRLF $sgData &= " iii;" & @CRLF $sgData &= " jjj := kkk OR" & @CRLF $sgData &= " ccc;" & @CRLF $sSearch = "ccc" ; "fff" ; "iii" ; Local $sMatch = StringRegExpReplace($sgData, "\s+([a-z]{3}).+\s+" & $sSearch & ";(\R)|\R*.*", "\1\2") ConsoleWrite(StringStripWS($sMatch, 2) & @CRLF) ; $STR_STRIPTRAILING (2) = strip trailing white space ; Or Local $aMatch = StringRegExp($sgData, "([a-z]{3}).+\s+" & $sSearch, 3) _DebugArrayDisplay($aMatch) EndFunc ;==>_Main
  2. Here are two one-liners that will return StringLeft() and StringRight() of all items in a 1D or 2D array. #include <array.au3> ; 1D Aarray Local $aArray[] = ["02", 1234, 23456789, "3456733333333333333333333"] ; Or, 2D Array ;Local $aArray[][] = [["02", 1234, 23456789, "3456733333333333333333333"],["ab", "cdefg","hijklmnop"]] _ArrayDisplay($aArray) $aArray1 = _ArrayFromString(StringRegExpReplace(_ArrayToString($aArray, "!"), "([^!\v]{3}).[^!\v]*", "\1"), "!") ; _ArrayAllItemsStringLeft _ArrayDisplay($aArray1, "Left") $aArray2 = _ArrayFromString(StringRegExpReplace(_ArrayToString($aArray, "!"), "[^!\v]*([^!\v]{3})", "\1"), "!") ; _ArrayAllItemsStringRight _ArrayDisplay($aArray2, "Right")
  3. Using StringReplace() is fine to blanket convert all commas. In case there are any commas in the string that don't need converting, here is a conditional converting method. Local $sOrigString = 'When a comma is between digits, replace with a point e.g. StringReplace("1,62918,", ",", ".")' Local $sString = StringRegExpReplace($sOrigString, "(?<=\d),(?=\d)", ".") Local $iReplacements = @extended MsgBox(4096, "", $iReplacements & " replacement" & _ ; $MB_SYSTEMMODAL is 4096 ($iReplacements = 1 ? " was" : "s were") & _ ; Allow for plural or singular grammatically. " made and the new string is:" & _ @CRLF & @CRLF & $sString) ; The RE Pattern:- ; "(?<=\d)," - (Lookbehind assertions) Match an occurrence of a comma, ",", that is preceded by a digit, "\d", but does not include the digit in the match; and, ; ",(?=\d)" - (Lookahead assertions) Matches a comma followed by a digit, "\d", but does not include the digit in the match. ; So, to match a particular comma to convert, there must be a digit on either side of the comma. ; Returns :- ; 1 replacement was made and the new string is: ; ; When a comma is between digits, replace with a point e.g. StringReplace("1.62918,", ",", ".") ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ : Replacement : Comma converted to point.
  4. This method has more accuracy than a 30 days a month method. #include <Date.au3> Local $sStartDate = "8/4/2021" ; Format is "D/M/YYYY", not US date format. Local $sEndDate = "9/6/2021" ; Format is "D/M/YYYY", not US date format. Local $sStart = _DateConvert($sStartDate, 0) Local $sEnd = _DateConvert($sEndDate, 0) ConsoleWrite("$sStart = " & $sStart & ' in format "YYYY/MM/DD"' & @CRLF) ConsoleWrite("$sEnd = " & $sEnd & ' in format "YYYY/MM/DD"' & @CRLF) Local $iNumMnths = _DateDiff('M', $sStart, $sEnd) ; Number of months between dates. Local $sStartPlusMnths = _DateAdd("M", $iNumMnths, $sStart) ; $sStartDatePlusMnths = Start Date plus number of months between dates. Local $iRemDays = _DateDiff('D', $sStartPlusMnths, $sEnd) ; Number of remaining days. Local $iTotalDays = _DateDiff('D', $sStart, $sEnd) ; Total number of days between dates. ConsoleWrite("(" & $iNumMnths & " month" & ($iNumMnths = 1 ? " " : "s ") & _ $iRemDays & " day" & ($iRemDays = 1 ? ")" : "s)") & " or " & _ $iTotalDays & " days" & @CRLF) ; ============== _DateConvert ================= ; If $US = 1 then format of $Date is in "[M]M/[D]D/YYYY" otherwise, ; If $US = 0 then format of $Date is in "[D]D/[M]M/YYYY" (not US date format) ; The converted Date out has format "YYYY/MM/DD" (for use in _Date...() AutoIt UDFs) ; Func _DateConvert($Date, $US = 1) Local $aTemp = StringSplit($Date, "/") Return StringFormat("%4i/%02i/%02i", $aTemp[3], ($US ? $aTemp[1] : $aTemp[2]), ($US ? $aTemp[2] : $aTemp[1])) EndFunc ;==>_DateConvert #cs ; Returns:- $sStart = 2021/04/08 in format "YYYY/MM/DD" $sEnd = 2021/06/09 in format "YYYY/MM/DD" (2 months 1 day) or 62 days #ce ; Returns:-
  5. This example function, _TimeRound(), will round up or down the time to the nearest specified minute in an hour, or, to a fraction of a minute. The default rounding number is 15 minute. #include <Date.au3> ; https://www.autoitscript.com/forum/topic/205759-guictrlcreatedate-using-every-quarter-hour-only/ ConsoleWrite("_TimeRound(""12:07"") equals " & _TimeRound("12:07") & " ; Note: There are no 'return' seconds present." & @CRLF) ConsoleWrite("_TimeRound(""12:8"") equals " & _TimeRound("12:8") & @CRLF) For $i = 0 To 68 * 60 Local $sTimeIncrement = StringRegExpReplace(_DateAdd('s', $i, "2021/04/02 12:00:00"), "(^\H+)\h", "") ConsoleWrite("_TimeRound(""" & $sTimeIncrement & """) equals " & _TimeRound($sTimeIncrement) & @tab) ConsoleWrite("_TimeRound(""" & $sTimeIncrement & """, 15/60) equals " & _TimeRound($sTimeIncrement, 15/60) & @CRLF) Next ; Description - Rounds time (default nearest 15 minutes of the hour, or, closest 15mins to $sTime +/- 7.5 mins). ; Parameters - $sTime - A time string, format in HH:MM[:SS] ; $iRoundedInMins - Rounding $sTime in minutes (default 15mins). For rounding to 15 seconds, have $iRoundedInMins = 15/60 (minutes). ; Returns - Time to nearest 15 mins in format HH:(00|15|30|45)[:00] If there are no "input" seconds present, then there are no "return" seconds present. ; Func _TimeRound($sTime, $iRoundedInMins = 15) Local $sPreDateTime = "2021/01/01 ", $iDecimalplaces = Int(Log(60 * $iRoundedInMins) / Log(10)), $iFactor = (60 * $iRoundedInMins) / (10 ^ $iDecimalplaces) Local $sHrZero = StringRegExpReplace($sTime, "(?<=\:)(.+)(?=$)", "00:00") ; Create Hour:00:00, where 'Hour' is the same hour as in $sTime. Local $bSecsPresent = StringRegExp($sTime, "\d+:\d+:\d+$") ; If secs are present, then $bSecsPresent is positive (True). Local $sDateTime = _DateAdd('s', Round(_DateDiff('s', $sPreDateTime & $sHrZero, $sPreDateTime & $sTime) / $iFactor, -$iDecimalplaces) * $iFactor, $sPreDateTime & $sHrZero) ; Nearest 900secs (15mins). Return StringRegExpReplace($sDateTime, "^\H+\h" & ($bSecsPresent ? "" : "|\:\d+$"), "") EndFunc ;==>_TimeRound #cs ; Returns:- _TimeRound("12:07") equals 12:00 ; Note: There are no 'return' seconds present. _TimeRound("12:8") equals 12:15 ... _TimeRound("13:07:22") equals 13:00:00 _TimeRound("13:07:22", 15/60) equals 13:07:15 _TimeRound("13:07:23") equals 13:00:00 _TimeRound("13:07:23", 15/60) equals 13:07:30 <--- Note: Time increments to 30sec because time's seconds > 22.5secs (15+15/2) or (30-15/2) _TimeRound("13:07:24") equals 13:00:00 _TimeRound("13:07:24", 15/60) equals 13:07:30 _TimeRound("13:07:25") equals 13:00:00 _TimeRound("13:07:25", 15/60) equals 13:07:30 _TimeRound("13:07:26") equals 13:00:00 _TimeRound("13:07:26", 15/60) equals 13:07:30 _TimeRound("13:07:27") equals 13:00:00 _TimeRound("13:07:27", 15/60) equals 13:07:30 _TimeRound("13:07:28") equals 13:00:00 _TimeRound("13:07:28", 15/60) equals 13:07:30 _TimeRound("13:07:29") equals 13:00:00 _TimeRound("13:07:29", 15/60) equals 13:07:30 _TimeRound("13:07:30") equals 13:15:00 _TimeRound("13:07:30", 15/60) equals 13:07:30 <--- Note: Time increments to 15min 00sec because time's min & sec equals 7.5min (15/2) _TimeRound("13:07:31") equals 13:15:00 _TimeRound("13:07:31", 15/60) equals 13:07:30 ... #ce
  6. I have been playing with this example for about a week, off and on. May this example help someone. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> #include <Array.au3> ; https://www.autoitscript.com/forum/topic/203556-_guictrlmonthcal-select-different-days/?do=findComment&comment=1462072 Global $g_idMemo Global $iFrmt = "other" ; Format MM/DD/YYYY ; or ; ;Global $iFrmt = "au" ; Format DD/MM/YYYY ; Example() Func Example() Local $idMonthCal GUICreate("Select Dates", 250, 340, -1, 20, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_SYSMENU)) Local $idMonthCal = GUICtrlCreateMonthCal("", 10, 10, 230, 160, $WS_BORDER) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetTip(-1, "Left mouse click on date to select") $g_idMemo = GUICtrlCreateEdit("", 10, 180, 230, 110) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKLEFT) GUICtrlSetTip(-1, "Drag bottom edge of the GUI window is possible") Local $idButSort = GUICtrlCreateButton("Sort (Asc/Desc)", 10, 295, 100, 20) GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT) GUICtrlSetTip(-1, 'Toggle ascending and descending date sort order.') Local $idButUniq = GUICtrlCreateButton("Unique", 120, 295, 50, 20) GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT) GUICtrlSetTip(-1, 'Remove duplicate dates.') Local $idButParse = GUICtrlCreateButton("Parse", 180, 295, 50, 20) GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT) GUICtrlSetTip(-1, "Change a range of dates (if present) to a list of dates" & @CRLF & _ 'eg. "12/08/202014/08/2020" or "12/08/2020 14/08/2020" or "14/08/2020:12/08/2020" or "12/08/2020 to 14/08/2020" will return:-' & @CRLF & _ '12/08/2020' & @CRLF & _ '13/08/2020' & @CRLF & _ '14/08/2020') Local $idButFormat = GUICtrlCreateButton("MM/DD/YYYY", 10, 318, 100, 20) GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT) GUICtrlSetTip(-1, 'Toggle date format between "DD/MM/YYYY" and "MM/DD/YYYY"') GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idMonthCal ;GUICtrlSetData($g_idMemo, GUICtrlRead($idMonthCal) & @CRLF, 1) GUICtrlSetData($g_idMemo, StringRegExpReplace(GUICtrlRead($idMonthCal), "(\d{4})/(\d{2})/(\d{2})", ($iFrmt = "au" ? "$3/$2/$1" : "$2/$3/$1") & @CRLF), 1) ; YYYY/MM/DD to (DD/MM/YYYY or MM/DD/YYYY) Case $idButSort _Parse() ; Default parameter is "1" to sort. And, will change a range of dates (if present) to a list of dates. Case $idButUniq _Unique() Case $idButParse _Parse(0) ; Parameter "0" will not sort, but will change a range of dates (if present) to a list of dates. Case $idButFormat GUICtrlSetData($idButFormat, ($iFrmt = "au" ? "MM/DD/YYYY" : "DD/MM/YYYY")) $iFrmt = ($iFrmt = "au" ? "other" : "au") GUICtrlSetData($g_idMemo, StringRegExpReplace(GUICtrlRead($g_idMemo), "(\d{2})/(\d{2})/(\d{4})", "$2/$1/$3"), "") EndSwitch WEnd GUIDelete() EndFunc ;==>Example ; Any two dates on the same line separated by any character(s) that are not a digit or a "/", ; will be replaced with a sequencial range of dates between the two dates. ; eg. "12/08/202014/08/2020" or "12/08/2020 15/08/2020" or "15/08/2020:12/08/2020" or "12/08/2020 to 15/08/2020" will return:- ; 12/08/2020 ; 13/08/2020 ; 14/08/2020 ; 15/08/2020 Func _Parse($iSort = 1) Local $Y, $M, $D, $iStart, $iEnd, $iStep = 1, $iIndex = 0 Local $aRet[1000][2] Local Static $iDesc = 1 If $iSort Then $iDesc = Not $iDesc ; Toggle ascending and descending date sort order. Local $a = StringRegExp(GUICtrlRead($g_idMemo), "[\d\V]+", 3) For $j = 0 To UBound($a) - 1 $aTemp = StringRegExp($a[$j], "[^\D]{2,4}", 3) ; Note: "[^\D]{2,4}" is faster than "\d{2,4}" If UBound($aTemp) = 6 Then ; Expand date range to date list. In 2D array, 1st column is sorting date,"y/m/d". 2nd column is formatted date, either "d/m/y" or "m/d/y"." $iStart = _DateToDayValue($aTemp[2], ($iFrmt = "au" ? $aTemp[1] : $aTemp[0]), ($iFrmt = "au" ? $aTemp[0] : $aTemp[1])) If @error Then ContinueLoop (Abs(MsgBox(16, "Error", "Error iInvalid range start date", 4))) ; Check valid date. $iEnd = _DateToDayValue($aTemp[2], ($iFrmt = "au" ? $aTemp[4] : $aTemp[3]), ($iFrmt = "au" ? $aTemp[3] : $aTemp[4])) If @error Then ContinueLoop (Abs(MsgBox(16, "Error", "Error invalid range end date", 4))) ; Check valid date. If $iStart > $iEnd Then $iStep = -1 For $i = $iStart To $iEnd Step $iStep _DayValueToDate($i, $Y, $M, $D) $aRet[$iIndex][0] = $Y & "/" & $M & "/" & $D $aRet[$iIndex][1] = ($iFrmt = "au" ? $D & "/" & $M : $M & "/" & $D) & "/" & $Y $iIndex += 1 Next Else If _DateIsValid($aTemp[2] & "/" & ($iFrmt = "au" ? $aTemp[1] & "/" & $aTemp[0] : $aTemp[0] & "/" & $aTemp[1])) = 0 Then _ ; Check valid date. ContinueLoop (Abs(MsgBox(16, "Error", "Invalid date: " & $a[$j], 4))) ; Check valid date. $a[$j] = StringRegExpReplace($a[$j], "([^\d/\v]+)", "") $aRet[$iIndex][0] = StringRegExpReplace($a[$j], "(\d{2})/(\d{2})/(\d{4})", ($iFrmt = "au" ? "$3/$2/$1" : "$3/$1/$2")) ; DD/MM/YYYY to YYYY/MM/DD for sorting on YYYY/MM/DD. $aRet[$iIndex][1] = $a[$j] $iIndex += 1 EndIf Next ReDim $aRet[$iIndex][2] If $iSort Then _ArraySort($aRet, $iDesc) _ArrayColDelete($aRet, 0) GUICtrlSetData($g_idMemo, _ArrayToString($aRet, @CRLF) & @CRLF) EndFunc ;==>_Parse Func _Unique() Local $a = StringRegExp(GUICtrlRead($g_idMemo), "[\d/]+", 3) $aU = _ArrayUnique($a) _ArrayDelete($aU, 0) GUICtrlSetData($g_idMemo, _ArrayToString($aU, @CRLF) & @CRLF) EndFunc ;==>_Unique
  7. This script sequentially renames all remaining sections of an .ini file after deleting one of the sections. Local $sFileName = "TestIni.ini" ; --------- Create a test .ini file ---------- If FileExists($sFileName) Then FileDelete($sFileName) FileWrite($sFileName, StringRegExpReplace(FileRead(@ScriptFullPath), "(?s)(^.*#cs\R|\R#ce.*$)", "")) ; -------- End of Create .ini file ----------- _DeleteSect($sFileName, 2) Run('Notepad.exe "' & $sFileName & '"') Func _DeleteSect($sFilePath, $Sect) IniDelete($sFilePath, $Sect) $aArray = IniReadSectionNames($sFilePath) For $i = 1 To $aArray[0] IniRenameSection($sFilePath, $aArray[$i], $i) Next ; Format and save .ini file Local $sFileContents = FileRead($sFilePath) FileDelete($sFilePath) FileWrite($sFilePath, StringStripWS(StringRegExpReplace($sFileContents, "\s*(\[\d+\])", @CRLF & @CRLF & "$1"), 3) & @CRLF) ; (1) = strip leading white spaces, and, (2) = strip trailing white spaces EndFunc ;==>_DeleteSect #cs [1] s = 1 m = 4 [2] h = 2 j = 7 k = 9 l = 22 r = 99 [3] a = 0 l = 111 y = 88 w = 90 [4] d =0 #ce
  8. This script, #include <Debug.au3> $file = @ScriptFullPath Local $aWords = StringRegExp(FileRead($file), "(?m)^\s*([^\s]+)\h*.*\R?", 3) _DebugArrayDisplay($aWords) returns #include $file Local _DebugArrayDisplay($aWords)
  9. Please notice in the opening post above, the image has the "Storlek" column circled in red. And just above the "k" in "Storlek" in the column header is an up-arrow character. This "up-arrow" character means that this column is sorted in ascending order. Click on the column header again, and the down-arrow character means the column is sorted in descending order.
  10. Another example for your amusement. #include <Array.au3> Local $aFiles[][2] = [["1.txt"], ["2.txt"], ["3.txt"]] Local $iMNCols = 0 ; Maximum Number of Columns (MNC) Local $sStr = "" ; This string will be converted into 2D array. ; Files to abbreviated strings For $i = 0 To UBound($aFiles) - 1 $aFiles[$i][1] = StringRegExpReplace(FileRead($aFiles[$i][0]), '(?:=+\R)?(\w+)[^=]+(?:=+\R?)?', "\1|") ; De-construct file format. StringReplace($aFiles[$i][1], "|", "|") $iExt = @extended ; @extended contains number of replacements in StringReplace() function. $iMNCols = ($iExt > $iMNCols ? $iExt : $iMNCols) ; Get Maximum Number of Columns Next ; String to 2D array For $i = 0 To UBound($aFiles) - 1 $sStr &= StringTrimRight($aFiles[$i][1], 1) & @CRLF ; StringTrimRight() removes trailing "|" . Next Local $aData[0][$iMNCols] _ArrayAdd($aData, StringStripWS($sStr, 2)) ; Append the three rows into the $aData array with $iMNCols number of columns. _ArrayTranspose($aData) ; Now array has $iMNCols number of rows, with three columns. ;_ArrayDisplay($aData, "", "", 0, Default, "1.txt|2.txt|3.txt") ; 2D array to file re-constructed string with numbers Local $sRet = "==" & @CRLF Local $r = 1 ; Counter For $j = 0 To UBound($aData) - 1 For $i = 0 To UBound($aData, 2) - 1 If $aData[$j][$i] <> "" Then $sRet &= $r & $aData[$j][$i] & @CRLF & $r & $aData[$j][$i] & @CRLF & "==" & @CRLF EndIf Next $r += 1 ; Increment $r Next ConsoleWrite(StringStripWS($sRet, 2) & @CRLF) ; Parameter flag (2) = strip trailing white spaces (@CRLF). Used the following files with the resultant output. 1.txt: == aa aa == aa aa == 2.txt: == bb bb == bb bb == bb bb == bb bb == bb bb == bb bb == 3.txt: == cc cc == cc cc == cc cc == cc cc == OUTPUT.txt: == 1aa 1aa == 1bb 1bb == 1cc 1cc == 2aa 2aa == 2bb 2bb == 2cc 2cc == 3bb 3bb == 3cc 3cc == 4bb 4bb == 4cc 4cc == 5bb 5bb == 6bb 6bb ==
  11. Another example. Local $sOrig = '?q=Kim+lo%E1%BA%A1i' MsgBox(0, "Conversion : ", "Original text: " & $sOrig & @CRLF & _ "Converted: " & BinaryToString(Binary(Execute('"' & StringRegExpReplace($sOrig, "(?i)%([0-9a-f]{2})", '" & Chr(0x${1})&"') & '"')), 4)) ; Returns:- ?q=Kim+loại
  12. Another example. #cs ; --------- Test Data ---------- Material B7E671143D244B ==================================== TEXT 2F3139D816C34D 1 TEXT B6A968EF2505A2 1 TEXT 35206697A04F91 1 TEXT EB485AF490D83D 1 TEXT 0DAB42294BD9B3 1 TEXT 3D6525BEE360E1 0 Material D6906B886B06E3 ==================================== TEXT 0CCECCCCFB62AE 1 TEXT 1E14CB29AB43F0 1 TEXT FB7F0DCE9B5950 1 But I have a new text file now the lines of which now are start with 0:, 1: and so on: sm_0 --------------- 0: dummy_gray 1: c_com_socksa_mt 2: c_com_socksa_tn 3: dummy_white 4: default_z 5: dummy_nmap 6: --- 7: --- sm_1 --------------- 0: c_com_prisoner_shoes_di 1: c_com_prisoner_shoes_mt 2: c_com_prisoner_shoes_tn 3: dummy_white 4: default_z 5: c_com_leatherb_rt 6: --- 7: --- #ce ; ----- End of Test Data ---------- #include <Array.au3> $_aName = StringRegExpReplace(FileRead(@ScriptFullPath), '(?is)(^.*#cs[^\R]*\R)|(\R#ce.*$)', "") ; Extract test data from script. ;ConsoleWrite( $_aName& @CRLF) $_aName = StringRegExp($_aName, '(?m)^(?:TEXT|\d+:\h)(.*$)', 3) ; Extract required text from test data. (Lines starting with "TEXT ", or, digits with a ": ". ConsoleWrite(_ArrayToString($_aName, @CRLF) & @CRLF) _ArrayDisplay($_aName)
  13. Late last year I came across the same problem. These are the two methods I found that worked. #include <Array.au3> Local $Paths = 'C:\Users\' & @CRLF & _ 'C:\EEC (1)\someother file' & @CRLF & _ 'C:\MSfree\' & @CRLF & _ 'C:\EEC (1)\' Local $sSearch = "C:\EEC" ; --------------------- Method 1 ---------------------------------- ; Check if "\E" is in $sSearch. If "\E" is present, replace "\E" with "\E\\E\Q", because of the "\Q" & $sSearch & "\E" in RE pattern. Local $sSearchA = (StringInStr($sSearch, "\E") ? StringReplace($sSearch, "\E", "\E\\E\Q") : $sSearch) ;ConsoleWrite("\Q" & $sSearchA & "\E" & @CRLF) Local $a = StringRegExp($Paths, "(\Q" & $sSearchA & "\E.*)", 3) _ArraySort($a) ;_ArrayDisplay($a) If UBound($a) > 1 Then For $i = 1 To UBound($a) - 1 ; Keep $a1[0] $sSearchB = (StringInStr($a[$i], "\E") ? StringReplace($a[$i], "\E", "\E\\E\Q") : $a[$i]) ConsoleWrite("\Q" & $sSearchB & "\E" & @CRLF) Local $sOutput = StringRegExpReplace($Paths, "(\Q" & $sSearchB & "\E\R?)", "") Next Else Local $sOutput = StringRegExpReplace($Paths, "(\Q" & $sSearchA & "\E.*\R?)", "") EndIf MsgBox(0, "\Q...\E", $sOutput) ; Or ; --------------------- Method 2 ---------------------------------- ; Beware "(1)", where (n) tests whether the capturing group with absolute number n matched. $sSearch = StringRegExpReplace($sSearch, "([\\()\.^$|\[\]{}*+?#])", "\\$1") ;ConsoleWrite($sSearch & @CRLF) Local $a1 = StringRegExp($Paths, "(" & $sSearch & ".*)", 3) _ArraySort($a1) ;_ArrayDisplay($a1) If UBound($a1) > 1 Then For $i = 1 To UBound($a1) - 1 ; Keep $a1[0] $sSearchC = StringRegExpReplace($a1[$i], "([\\()\.^$|\[\]{}*+?#])", "\\$1") ConsoleWrite($sSearchC & @CRLF) Local $sOutput = StringRegExpReplace($Paths, "(" & $sSearchC & "\R?)", "") Next Else Local $sOutput = StringRegExpReplace($Paths, "(" & $sSearch & ".*\R?)", "") EndIf MsgBox(0, "\\,(,)", $sOutput) #cs ; Both methods return:- C:\Users\ C:\MSfree\ C:\EEC (1)\ #ce
  14. Here is another method in this example. #include <Array.au3> Local $aData[][] = [ _ [""], _ [""], _ [1, "x", "w", "w", 5], _ [1, "x", "w", "w", 5], _ ["w", "x", 3, 4, "x"], _ [""]] Local $sAppendNewRow = "2|0|1|1" Local $sAppendNBRows = "2" ; String to append to Non-Blank rows. ReDim $aData[UBound($aData, 1) + 1][UBound($aData, 2) + 1] ; Re-dimension array with one extra row and one extra column. ; -------- Add last row -------- Local $aLastRow = StringSplit($sAppendNewRow, "|", 2) ; $STR_NOCOUNT (2) For $i = 0 To UBound($aLastRow) - 1 $aData[UBound($aData) - 1][$i] = $aLastRow[$i] Next ; ---Append $sAppendNBRows value to the end of each non-blank row. --- For $i = 0 To UBound($aData) - 1 For $j = UBound($aData, 2) - 2 To 0 Step -1 If $aData[$i][$j] <> "" Then $aData[$i][$j + 1] = $sAppendNBRows ; Add $sAppendNBRows to previous column, "$j + 1" in row, "$i". ExitLoop EndIf Next Next _ArrayDisplay($aData)
  15. Your new question in this thread probably would have got more attention by creating a new thread. Here is one example of updating an array - the first method I thought of. There are surely other methods. #include <Array.au3> Local $aData[][] = [ _ [""], _ [""], _ [1, "x", "w", "w", 5], _ [1, "x", "w", "w", 5], _ ["w", "x", 3, 4, "x"], _ [""]] Local $sAppendNewRow = "2|0|1|1" Local $sAppendNBRows = "2" ; String to append to Non-Blank rows. ; --- Append new last row.--- _ArrayAdd($aData, $sAppendNewRow) ; --- Append new column ---- ReDim $aData[UBound($aData, 1)][UBound($aData, 2) + 1] ; Re-dimension Array with one extra column. ; ---Append $sAppendNBRows value to the end of each non-blank row. --- Local $sStrData = _ArrayToString($aData) ; Assign contents of array to string for later RE string manipulation. ;ConsoleWrite($sStrData & @CRLF) ; See workings. Local $aData[0][UBound($aData, 2)] ; Re-assign the array, $aData, with zero rows. _ArrayAdd($aData, StringRegExpReplace($sStrData, "(?m)([^\|\v]+\|)(\|{0," & (UBound($aData, 2) - 1) & "})$", "${1}" & $sAppendNBRows & "${2}")) ; Append a "2" to all non-blank rows. ;ConsoleWrite(StringRegExpReplace($sStrData, "(?m)([^\|\v]+\|)(\|{0," & (UBound($aData, 2) - 1) & "})$", "${1}2${2}") & @CRLF) ; See workings. _ArrayDisplay($aData)
×
×
  • Create New...