rony2006

Remove array elements where doesn't contain....

8 posts in this topic

#1 ·  Posted

Hello,

I have a 2d array and I want to remove all array elements that doesn't contain "csv" substring inside.

 

How can I do this please?

Share this post


Link to post
Share on other sites



#2 ·  Posted

rony2006,

What have you tried that has not worked?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

I tried this code:

 

Local $aArray[5][5] = [[0, 1, 2, 1, 0], _
        [4, 5, 5, 4, 2], _
        [4, 1, 3, 1, 3], _
        [0, 3, 2, 1, 0], _
        [1, 5, 5, 4, 1]]
_ArrayDisplay($aArray, "2D array")

Local $aResult = _ArrayFindAll($aArray, 0, Default, Default, Default, Default, 4)
_ArrayDisplay($aResult, "Found in Column 4")

 

Modified in 

Local $aResult = _ArrayFindAll($aArray, 0, Default, Default, Default, "csv", 4)

$aResult cotains a lot of urls to .csv files.

Share this post


Link to post
Share on other sites

#4 ·  Posted

So what ?
_ArrayFindAll returns an array of indexes. Just use this array as $vRange param in _ArrayDelete  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

_ArrayFindAll  doesn't return me any result. I don't understand why.

Share this post


Link to post
Share on other sites

#6 ·  Posted

rony2006,

Then give us an actual example of the data in your array and the code you are using to find whatever it is you are looking for. Otherwise how do you expect us to be able to help you?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Hello,

$oWorkbook = "C:\Users\Marian\Downloads\Rapoarte Electro\"&$aFileList[1]
$sFileOpenDialog = $oWorkbook

; Create application object and open an example workbook
Local $oExcel = _Excel_Open(False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookOpen($oExcel, $sFileOpenDialog)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf





; *****************************************************************************
; Read the formulas of a cell range on sheet 2 of the specified workbook
; *****************************************************************************
Local $aResult = _Excel_RangeRead($oWorkbook, Default,Default, 2)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Data successfully read." & @CRLF & "Please click 'OK' to display the formulas of cells A1:C1 of sheet 2.")

;_ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead Example 2 - Cells A1:C1 of sheet 2")

With this code I make a csv file to 2d array. The csv file looks like the one attached.

Then I want to upload to a mysql database all links (only one column) that contains links to .csv files.

 

Now I upload all data to mysql and then I delete all that doesn't contain %csv%.

$sMySqlStatement = "DELETE FROM linklist WHERE link  NOT LIKE '%csv%';"
 If Not _EzMySql_Exec($sMySqlStatement) Then
 _GUICtrlEdit_AppendText($input1, @CRLF &$sMySqlStatement)
            MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
            Exit
            EndIf

 

www.cenace.gob.mx_9th_Oct_2017 (6).csv

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

A nice way would be to extract first the wanted links to a new (temp) .csv before uploading   :)

#Include <Array.au3>
#include <File.au3>

$s = FileRead("www.cenace.gob.mx_9th_Oct_2017 (6).csv")

$res = StringRegExp($s, '(?m)^"([^"]+csv)' , 3)
_ArrayDisplay($res)

_FileWriteFromArray(@scriptdir & "\new.csv", $res)

Edit
This keeps the quotes around the links

$res = StringRegExp($s, '(?m)^("[^"]+csv")' , 3)

 

Edited by mikell
1 person likes this

Share this post


Link to post
Share on other sites

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