Jump to content

Recommended Posts

Posted

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)

 

Posted (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 by Davidowicza
Posted (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 by TheXman
Added comment and corrected ForNext
Posted

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...