shornw Posted July 14, 2010 Share Posted July 14, 2010 Hi all is it possible to read a comma seperated file to an array so that each item becomes a seperate array column. I have a .txt file which is written when users logon to the domain, below is a typical line: SmithF, PC1234, Fred Smith, Finance, 1234 JonesB, PC3456, Bill Jones, Sales, 7890 What I want to do is read this line into an array so that each item is read into a seperate column. If I use _FileReadToArray every item on each line is written into one single column. Sorry if this is obvious Thanks for looking [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 14, 2010 Moderators Share Posted July 14, 2010 shornw,Do it in 2 steps within an outer loop: - 1. Use StringSplit to get the next single line into a 1D array.- 2. Use an inner loop to read the elements from that 1D array into the correct elements of the final 2D array. 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...
JohnOne Posted July 14, 2010 Share Posted July 14, 2010 (edited) #include <Array.au3> ;just to show array $sString = "SmithF, PC1234, Fred Smith, Finance, 1234" $atemp = StringSplit($sString,",",2) Local $aArray[1][UBound($atemp)] For $i = 0 to UBound($atemp) -1 $aArray[0][$i] = $atemp[$i] Next $atemp = 0 _ArrayDisplay($aArray)I'm in a jovial mood today. Edited July 14, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Juvigy Posted July 14, 2010 Share Posted July 14, 2010 I was curious , so .. include <Array.au3> ;just to show array $sString = "SmithF, PC1234, Fred Smith, Finance, 1234,Test2, PC1235, Test 2, Germany, 1235" $atemp = StringSplit($sString,",",2) Local $aArray[1][5] $i=0 $b=0 Do For $j = 0 to 4 $aArray[$b][$j] = $atemp[$i] $i=$i+1 Next ReDim $aArray[UBound($aArray)+1][5] $b=$b+1 Until $i>UBound($atemp)-1 _ArrayDisplay($aArray,$i) Link to comment Share on other sites More sharing options...
shornw Posted July 14, 2010 Author Share Posted July 14, 2010 Thanks for your replies, very helpful. I hit a wall in another pway now. My thinking went this way: $sString = "SmithF, PC1234, Fred Smith, Finance, 1234" $split = StringSplit($sString, ",") If $split[1] = @UserName And $split[2] = @ComputerName Then Exit Can anyone tell me why, although $split[1] returns the username and $split[2] returns the PC name the If/Then will not work. Thanks again [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
JohnOne Posted July 14, 2010 Share Posted July 14, 2010 Nope, works fine for me. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Mat Posted July 14, 2010 Share Posted July 14, 2010 Is that a bit of space I see after the commas? AutoIt Project Listing Link to comment Share on other sites More sharing options...
shornw Posted July 14, 2010 Author Share Posted July 14, 2010 Mat...... can you come and shoot me. That much stupidity doesn't deserve to live!!! Thank you, this is the last bit of a huge data collection script which needs to be completed by Friday...and I have to leave at 12 tomorrow. REALLY much appreciated. I love this forum [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Link to comment Share on other sites More sharing options...
Mat Posted July 14, 2010 Share Posted July 14, 2010 Mat...... can you come and shoot me. That much stupidity doesn't deserve to live!!! You'll only really find bugs like that when you know what you're looking for to start with. The good news is that you won't make that mistake again, so you can only be shot once AutoIt Project Listing 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