BasementDweller Posted February 1, 2019 Share Posted February 1, 2019 I'm having troubles replacing existing values in one column of a 2D array. I would like to repalce all "11" in Col4 with "20". There are 400 rows that contain "11" in Col4. I am using _ArrayInsert to try to accomplish this. The result I get from the below script, though, creates many interspersed empty rows with a "20" in Col4 of the first empty row. The help file for _ArrayInsert says I should be able to "Insert a new value at the specified position of a 1D or 2D array" but I'm not seeing a way to properly do that. I think I've tried all the options for _ArrayInsert. I've also gone through much of the help file looking for a different way to replace 2D array values and haven't found anything. I did find a couple topics in the fourm that were sort of similar to this, but I didn't really get any clues. I'm hoping someone can give me a few pointers. #include <Array.au3> #include <csv.au3> $path = @ScriptDir&"\" $aArray=_ParseCSV($path & "MyData.csv") _ArrayDisplay($aArray) $vRange=_ArrayFindAll($aArray, "11", Default, Default, Default, Default, 4) _ArrayDisplay($vRange) _ArrayInsert ($vRange,0,ubound($vRange)) _ArrayDisplay($vRange) $vValue=("20") $iStart=("4") $iForce=("3") _ArrayInsert($aArray, $vRange , $vValue, $iStart, $iForce) _ArrayDisplay($aArray) Link to comment Share on other sites More sharing options...
Davidowicza Posted February 1, 2019 Share Posted February 1, 2019 (edited) I believe $vRange has to be a delimited string in the parameters of _ArrayInsert and not an array. Use _ArraytoString to convert $vRange before calling _ArrayInsert. Edit: I realized this could is probably wrong... So ignore unless I am now overthinking it. Edited February 1, 2019 by Davidowicza Link to comment Share on other sites More sharing options...
TheXman Posted February 1, 2019 Share Posted February 1, 2019 (edited) @BasementDweller Something like this maybe? #include <Array.au3> #include <csv.au3> $path = @ScriptDir&"\" $aArray=_ParseCSV($path & "MyData.csv") _ArrayDisplay($aArray) ;Change value, in column with index of 4, from 11 to 20 For $i = 0 To UBound($aArray) - 1 If $aArray[$i][4] = "11" Then $aArray[$i][4] = "20" Next _ArrayDisplay($aArray) You didn't supply a representation of the data, so I don't know if the index that I used is correct. So just adjust it as needed. Edited February 1, 2019 by TheXman Added comment and corrected ForNext CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
BasementDweller Posted February 5, 2019 Author Share Posted February 5, 2019 Hi again TheXman. Your script worked. Thanks for your help! Link to comment Share on other sites More sharing options...
TheXman Posted February 5, 2019 Share Posted February 5, 2019 You're welcome! CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman 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