Nubie Posted March 25, 2020 Share Posted March 25, 2020 when I try make delimiter in _FileReadToArray, I found a problem, it'll not work if last lines have more than a empty lines #include <Array.au3> #include <File.au3> Local $aFileName _FileReadToArray(@ScriptDir & "\test.txt", $aFileName, 0, ",") _ArrayDisplay($aFileName) work: aa,bb 11,22 work: aa,bb 11,22 [empty] not work: aa,bb 11,22 [empty] [empty] I'm not sure this's bug or by I'm not fully understand about _FileReadToArray For temp, I must rewrite that file with delete all empty last lines, then I can use _FileReadToArray. feeling stupid. Could someone help me a smarter way? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 25, 2020 Moderators Share Posted March 25, 2020 Nubie, You are trying to read a delimited line file with lines that do not contain a delimiter - so the function fails and will return @error set to 3 as explained in the Help file. You either need to delete the empty lines or add a delimiter to them - then each line of the file will "match" and the function will work. And before you ask, the function was designed that way to warn of files which had incorrect delimiter formatting. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nubie Posted March 25, 2020 Author Share Posted March 25, 2020 Thanks sir for explain But I'm still stucking for find a smarter way without rewrite file. Tried this but get new problem. How to split array when rows and column is unknow amounts #include <Array.au3> Local $aFileName $aFileName = FileReadToArray(@ScriptDir & "\test.txt") _ArrayDelete($aFileName , _ArrayToString(_ArrayFindAll($aFileName , ""))) _ArrayDisplay($aFileName) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 25, 2020 Moderators Share Posted March 25, 2020 Nubie, Try this: #include <Array.au3> #include <File.au3> Global $aArray ; Reads file into array of arrays _FileReadToArray("Test.txt", $aArray, $FRTA_INTARRAYS, ",") ; Find maximum nunber of delimiter per line $iMax_Delim = 0 For $i = 0 To UBound($aArray) - 1 $iElements = UBound($aArray[$i]) If $iElements > $iMax_Delim Then $iMax_Delim = $iElements EndIf Next ; Create a suitably sized array to hold the expanded elements Global $aExpanded[UBound($aArray)][$iMax_Delim] ; And fill it For $i = 0 To UBound($aArray) - 1 For $j = 0 To UBound($aArray[$i]) - 1 $aExpanded[$i][$j] = ($aArray[$i])[$j] Next Next ; And here it is _ArrayDisplay($aExpanded, "", Default, 8) Any use? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nubie Posted March 25, 2020 Author Share Posted March 25, 2020 yes, it's work fine do what I want. Thanks very much 😁 Link to comment Share on other sites More sharing options...
Nine Posted March 25, 2020 Share Posted March 25, 2020 (edited) Another option IF the number of items per row are equal : #include <Array.au3> Local $sString = StringRegExpReplace (FileRead ('Test.txt'),"(?m)^\s*$\R?", '') StringReplace (StringMid ($sString,1,StringInStr ($sString,@CRLF)),",", "") Local $aArray[0][@extended+1] _ArrayAdd ($aArray,$sString,0,",") _ArrayDisplay ($aArray) Not sure about the speed though. You may want to compare with M23 solution. Edited March 25, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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