# Thread: 2-d arrays, indices info?

1. ## 2-d arrays, indices info?

User Wendy Richardson (rwendy@us.ibm.com.nospam) posted:

Does anyone know of a simple way to get a list of
the "string indices" in a 2-d array? i.e. If I have the array
members below, but didn't know ahead of time
that "aString" and "anotherString" were array indices,
is there a simple way to optain these? I have a rather
roundabout way, but maybe someone else has the

a[ 1 , "aString"]
a[ 1 , "anotherString"]
a[ 2 , "aString"]
a[2 , "anotherString"]

THanks so much.
Wendy

Wendy Richardson
QA Automation Tools
919-543-3514 T/L 444-3514

2. ## Re: 2-d arrays, indices info?

------_=_NextPart_001_01C1CE97.D7BC8BC5
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This will display an index 'glob' that can be parsed based on a known speci=
al character
=20
for(i in a)
printf i;
=20
Will look something like this:=20
1|"aString"
1|"anotherString"
2|"aString"
2|"anotherString"

You can parse the string based on the special character (I don't recall wha=
t it is, it's not a fence post) to get each index.
=20

3. ## Re: 2-d arrays, indices info?

Here's something I just threw together:

<pre># return comma-separated list of second indexes:
public function get2ndIndex(inout someArray[], out listOfIndexes) {
static indexes[];
static list[];
static ix;
listOfIndexes = "";
for (ix in someArray) {
split(ix,indexes,"\034");
list[indexes[2]] = 1;
}
listOfIndexes = "";
for(ix in list) {
if(listOfIndexes != "") {
listOfIndexes = listOfIndexes & ",";
}
listOfIndexes = listOfIndexes & ix;
}
return(listOfIndexes);
}

### MAIN ###
# Test the function:
array[1,"string1"] = "test1-1";
array[1,"string2"] = "test1-2";
array[1,"string3"] = "test1-3";
array[2,"string1"] = "test2-1";
array[2,"string2"] = "test2-2";
array[1,"string3"] = "test2-3";

indexes = get2ndIndex(array);

pause(indexes); </pre>

------------------
Charles Reace

charles{DOT}reace{AT}verizon{DOT}net

[This message has been edited by Charles Reace (edited 03-18-2002).]

4. ## Re: 2-d arrays, indices info?

User Wendy Richardson (rwendy@us.ibm.com.nospam) posted:

Yes, I have that (it's ascii 28). but... still I have a clunky little
function
where it seems there might be something easier. (I have to split, check
and
see if the particular indice has "already" been found, etc);

Thanks

Wendy

Wendy Richardson
QA Automation Tools
919-543-3514 T/L 444-3514

"Richard Weber" <rweber@houston.ds.adp.com> on 03/18/2002 11:13:29 AM

To: <winrunner@yahoogroups.com>
cc:
Subject: RE: [winrunner] 2-d arrays, indices info?

This will display an index 'glob' that can be parsed based on a known
special character

for(i in a)
*** printf i;

Will look something like this:
1|"aString"
1|"anotherString"
2|"aString"
2|"anotherString"

You can parse the string based on the special character (I don't recall
what it is, it's not a fence post) to get each index.

5. ## Re: 2-d arrays, indices info?

------_=_NextPart_001_01C1CEA1.774C729F
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Well, that's how it's done. A nifty trick to keep track of 'already existing' items is to create an array where the index is the item (the value could be the count of that item if need be). This way there is no work involved at all to store found items. I do somthing similar in a function that returns the array size for multi-dimensional arrays.

-----Original Message-----
From: Wendy Richardson [mailto:rwendy@us.ibm.com]
Sent: Mon 3/18/2002 10:27 AM
To: winrunner@yahoogroups.com
Cc:
Subject: RE: [winrunner] 2-d arrays, indices info?

Yes, I have that (it's ascii 28). but... still I have a clunky little
function
where it seems there might be something easier. (I have to split, check
and
see if the particular indice has "already" been found, etc);

Thanks

Wendy

Wendy Richardson
QA Automation Tools
919-543-3514 T/L 444-3514

"Richard Weber" <rweber@houston.ds.adp.com> on 03/18/2002 11:13:29 AM

To: <winrunner@yahoogroups.com>
cc:
Subject: RE: [winrunner] 2-d arrays, indices info?

This will display an index 'glob' that can be parsed based on a known
special character

for(i in a)
printf i;

Will look something like this:
1|"aString"
1|"anotherString"
2|"aString"
2|"anotherString"

You can parse the string based on the special character (I don't recall
what it is, it's not a fence post) to get each index.

6. ## Re: 2-d arrays, indices info?

User condoman1944 (bneild@travelers.com.nospam) posted:

I came to this party a little late, but did you just want to see if
the string index was already in the array? If so, then use:
if (x in a) blah blah...

--- In winrunner@y..., "Wendy Richardson" <rwendy@u...> wrote:

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.