Jump to content

Add "" to data inside 2d array


chachew
 Share

Recommended Posts

I have an array that will populate data but i need to put "" around the data

Example:

Original array

Dim $array[1][7]

$array[0][0]=ControlListView("CallStatus","","TListView2","GetText",0,1)

$array[0][1]=ControlListView("CallStatus","","TListView2","GetText",0,2)

$array[0][2]=ControlListView("CallStatus","","TListView2","GetText",0,3)

$array[0][3]=ControlListView("CallStatus","","TListView2","GetText",0,4)

$array[0][4]=ControlListView("CallStatus","","TListView2","GetText",0,5)

$array[0][5]=ControlListView("CallStatus","","TListView2","GetText",0,6)

$array[0][6]=ControlListView("CallStatus","","TListView2","GetText",0,7)

Can i add " " around each set of data in the array

Link to comment
Share on other sites

It's unclear to me just why you want to enclose strings (I assume you populate it with strings) data in your array.

If your usage if for producing a CSV line, you can use something like this:

$csv = '"' & _ArrayToString($myArray, '","') & '"'
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

It's unclear to me just why you want to enclose strings (I assume you populate it with strings) data in your array.

If your usage if for producing a CSV line, you can use something like this:

$csv = '"' & _ArrayToString($myArray, '","') & '"'

Im reading infor from a ListView and then converting that to a string so i can have an html page display that data via javascript.

Link to comment
Share on other sites

When ever you use two sets of " you will "escape" it and it will become a piece of text inside the variable. So $hello = """This is a test""" will look like "This is a test" because for a string to work it needs quotes of some kind like "text" but if you want quotes to be part of the data you double the quotes so you end up with 3 of them either side, the single first ones at the start and end define the begining and end of the variable whereas the next two on both side translate to one quote in the actual data. Either that or you can use a mixture of apostrophe and quotes like $hello = 'hello "this" part right there is a test' Since your string is defined using ' instead of " your " does not need to be "escaped" by doubling it up to have it show up in the data. If you wanted to use ' to define your string and also have ' as part of your text, you need to double it up as before $test = 'this is Brian''s seat'

You could do something like

$array[1] = '"' & $array[1] & '"'

$array[1] = """" & $array[1] & """"

which "should" do the same thing, first one is a single " encapsulated with a ' either side, the second is " either side with a double quote "" making it appear as part of the data.

Edited by Morthawt
Link to comment
Share on other sites

Here is a working example.

Note the symbiotic relationship between the For - Next loop and the array.

#include <Array.au3>

WinActivate("Program Manager")
WinWaitActive("Program Manager")

Local $iNum = ControlListView("Program Manager", "", "", "GetItemCount")
Local $array[$iNum][1]

For $i = 0 To $iNum - 1
    $array[$i][0] = '"' & ControlListView("Program Manager", "", "", "GetText", $i) & '"'
Next

_ArrayDisplay($array, "Desktop Items")
Link to comment
Share on other sites

So how would i simultaneously use the For loop to get row and column, i used you example and i can get the rows no problem

#include <Array.au3>
 
Local $iRow = ControlListView("CallStatus","",3, "GetItemCount")
Local $iCol = "7"
Local $array[$iRow][$iCol]
For $i = 0 To $iRow - 1
    $array[$i][0] = '"' & ControlListView("CallStatus","",3, "GetText", $i) & '"'
Next
_ArrayDisplay($array,"Test")

But if i also try to get the columns...its not working..my thinking is obviously wrong

#include <Array.au3>
 
Local $iRow = ControlListView("CallStatus","",3, "GetItemCount")
Local $iCol = "7"
Local $array[$iRow][1]
For $i = 0 To $iRow - 1
    $array[$i][0] = '"' & ControlListView("CallStatus","",3, "GetText", $i) & '"'
Next
 
Local $iCol = ControlListView("CallStatus","",3, "GetSubItemCount")
For $i2 = 0 To $iCol - 1
$array[$i][$i2] = '"' & ControlListView("CallStatus","",3, "GetText", $i2) & '"'
Next
_ArrayDisplay($array,"Test")
Edited by chachew
Link to comment
Share on other sites

Here is an example of the commonly used method to fill a 2D array using two For - Next loops.

#include <Array.au3>

Local $sWinTitle = @ProgramFilesDir & "\AutoIt3"
Run("Explorer.exe /e," & $sWinTitle)
WinWaitActive($sWinTitle)

Local $iNum = ControlListView($sWinTitle, "", "SysListView321", "GetItemCount")
Local $array[$iNum][3]

For $r = 0 To $iNum - 1  ; On each row
    For $c = 0 To UBound($array, 2) - 1  ; Enter each and every column, $c, on the row, $r.
        $array[$r][$c] = ControlListView($sWinTitle, "", "SysListView321", "GetText", $r, $c)
    Next
Next

_ArrayDisplay($array)

If WinExists($sWinTitle) Then WinClose($sWinTitle) ; Close Windows Explorer
Link to comment
Share on other sites

I had this working now its broken for some reason...reads the row and column count but pulls no text??

#include <Array.au3>
$str1='{ "callqueue": ['
$str2='] }'
;~ While ProcessExists("CallStatus.exe")
Local $iRow = ControlListView("CallStatus","",3, "GetItemCount")
Local $iCol = ControlListView("CallStatus","",3, "GetSubItemCount")
Local $array[$iRow][$iCol]
For $r = 0 To $iRow - 1
    For $c = 0 To UBound($array, 2) - 1  ; Enter each and every column, $c, on the row, $r.
        $array[$r][$c] = ControlListView("CallStatus","",3,"GetText", $r, $c)
    Next
Next
_ArrayDisplay($array,"Test")
;~ WEnd

The CallStatus i'm reading from attached

CallStatus.exe

Edited by chachew
Link to comment
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
 Share

  • Recently Browsing   0 members

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