Stoex Posted May 2, 2014 Share Posted May 2, 2014 I'm using the below code in an array and everything works as it should, including the element count(by default) in the 0 row. I want to eliminate that count and have tried using: $STR_NOCOUNT but the count is still returned in row 0. The documentation says I should be able to use $STR_NOCOUNT. The examples don't fit what I'm doing. $csv = FileRead ("C:ABC ExpressXYZ.csv") $csv = StringStripWS($csv, 7) $rows = StringSplit($csv, @CRLF ) Seems straight forward but I'm hitting a brick wall. What should I be doing with $STR_NOCOUNT to make this work? Thanks! Link to comment Share on other sites More sharing options...
JohnOne Posted May 2, 2014 Share Posted May 2, 2014 Works fine for me. #include <Array.au3> #include <MsgBoxConstants.au3> $str = "wwwwwwwwwwwwwwwwwwwwwwww" $astr = StringSplit($str, "", $STR_NOCOUNT) _ArrayDisplay($astr) 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...
Stoex Posted May 2, 2014 Author Share Posted May 2, 2014 As a beginner, I would have to say if you are not comparing apples to apples, the end results could be different. But thanks. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 2, 2014 Moderators Share Posted May 2, 2014 Not exactly possible for us to compare "apples to apples" unless you plan on posting your csv file "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! Link to comment Share on other sites More sharing options...
mikell Posted May 2, 2014 Share Posted May 2, 2014 Here are apples #include <Array.au3> $str = "ww" &@crlf& "ww" &@crlf& "ww" &@crlf& "ww" $astr = StringSplit($str, @crlf, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT _ArrayDisplay($astr) Link to comment Share on other sites More sharing options...
JohnOne Posted May 2, 2014 Share Posted May 2, 2014 As a beginner, I would have to say if you are not comparing apples to apples, the end results could be different. But thanks. You can compare apples to daleks if you like the array count is simply not returned in a resulting array if you use the flag. 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...
czardas Posted May 2, 2014 Share Posted May 2, 2014 You could try my CSV split UDF. '?do=embed' frameborder='0' data-embedContent>> operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
BrewManNH Posted May 2, 2014 Share Posted May 2, 2014 If you have the latest beta version, you can use _FileReadToArray, doing something like this. It will read in a character delimited file, for example a CSV file, and split it to a 2D array for you. #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Define a variable to pass to _FileReadToArray. Local $aArray = _FileReadToArray("C:\ABC Express\XYZ.csv", $FRTA_NOCOUNT, ",") ; comma delimited file ; Read the current script file into an array using the variable defined previously. ; $iFlag is specified as 0 in which the array count will not be defined. Use UBound() to find the size of the array. If @error Then MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file. EndIf ; Display the array in _ArrayDisplay. _ArrayDisplay($aArray) EndFunc ;==>Example If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 2, 2014 Share Posted May 2, 2014 (edited) Note Stoex that Array[0] will be filled no matter what flag you use. If you use $STR_NOCOUNT (or 2), it (Array[0]) wont be filled with the count of returned elements, but with the first element.Local $sString = "this is a string" Local $aString1 = StringSplit($sString, " ") Local $aString2 = StringSplit($sString, " ", 2) MsgBox(0, "", "Array[0] - " & $aString1[0] & @CRLF & "Array[0] - " & $aString2[0]) Edited May 2, 2014 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2014 Share Posted May 2, 2014 (edited) If you have the latest beta version, you can use _FileReadToArray, doing something like this. It will read in a character delimited file, for example a CSV file, and split it to a 2D array for you. Interesting! I imagine this doesn't cater for standard csv variants: commas, line breaks and double quotes enclosed within fields. Edited May 2, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
BrewManNH Posted May 2, 2014 Share Posted May 2, 2014 It's a basic CSV split, for those that just need a file with the standard delimiters used. It doesn't pay attention to quotes around items that might have the delimiter inside, e.g. "test, test1, test2" will be split like "test test1 test2" You'd need a purpose built function for that, such as the one you posted. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2014 Share Posted May 2, 2014 (edited) I still think it's quite useful as a feature. It could go to 16 dimensions with a few tweaks. Edited May 2, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Stoex Posted May 2, 2014 Author Share Posted May 2, 2014 All interesting comments. Here is the code I referred to. Site won't let me upload CSV file, but its simple as the comment in the code mentions. No matter what I tweak, I keep getting the element count in row 0. So being new at this, I must be overlooking something. Other than the element count in row 0, everything else is fine. #include <Array.au3> #include <File.au3> Local $iCount = 0, $sTemp Local $ABC[200][5] ;state array $csv = FileRead ("C:\ABC Express\XYZ.csv") ;5 data fields separated by comma $csv = StringStripWS($csv, 7) $rows = StringSplit($csv, @CRLF ) Dim $ABC[$rows[0] + 1][5 + 1] $ABC[0][0] = $rows[0] For $i = 1 to $rows[0] $temp = StringSplit($rows[$i], ",",2 ) For $j = 0 to UBound($temp) - 1 $ABC[$i][$j] = $temp[$j] ; if $j = 4 then $ABC [$i] [$j] = number($ABC [$i] [$j]) EndIf Next Next _ArrayDisplay($ABC, " Result") Link to comment Share on other sites More sharing options...
BrewManNH Posted May 2, 2014 Share Posted May 2, 2014 You're using stringsplit without the $STR_NOCOUNT parameter. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
czardas Posted May 2, 2014 Share Posted May 2, 2014 (edited) Have you tried: $rows = StringSplit($csv, @CRLF, 3) ; Edit I guess I was reading ther wrong line. You code should not be returning the count in the first element. Edited May 2, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Stoex Posted May 2, 2014 Author Share Posted May 2, 2014 in the code: $rows = StringSplit($csv, @CRLF ) ;not using $STR_NOCOUNT parameter. But 4 lines later.. $temp = StringSplit($rows[$i], ",",2 ) ; <<<< 2 is used for the $STR_NOCOUNT parameter as per format for StringSplit.. And I just tried $rows = StringSplit($csv, @CRLF,3 ) ; as suggested and it then only returns row 0 and nothing else. Perplexing it works fine with the exception of returning the element count. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 2, 2014 Share Posted May 2, 2014 MIssed that, sorry. I see the problem though. $ABC[0][0] = $rows[0] For $i = 1 to $rows[0] You're putting the count into $ABC yourself in that code, so no wonder it has the count there. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Stoex Posted May 2, 2014 Author Share Posted May 2, 2014 BrewManNH You are way more advanced than I am, so I'm a little confused now. how is that wrong? If i change it to ABC[2] [0] =$row [0] ???? Thanks for any enlightenment you can spare. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 2, 2014 Share Posted May 2, 2014 You're complaint was that you were getting the count in the array even when you are using StringSplit with the no count value. Where are you getting the split count showing up? In $ABC[1][0], $ABC[2][0] etc. or in $ABC[0][0]? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Stoex Posted May 2, 2014 Author Share Posted May 2, 2014 $ABC [0] [0] 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