Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Comparing two List of String

1. ## Comparing two List of String

I have two lists of string. Is there a simple way to print out the differences between two lists.

------------------

2. ## Re: Comparing two List of String

Here's a ListCompare function I wrote sometime back

whoops! you'll have to comment out the DPrint call. This is one of our debug print statements. It wont compile with this in it.
------------------

[This message has been edited by TonyM (edited 02-28-2002).]

[This message has been edited by TonyM (edited 02-28-2002).]

3. ## Re: Comparing two List of String

Shows the differences in two Lists of strings ?

This a a basic part of SilkTest, the Verify() function.
Be sure to wrap it in a do ... except or your test will stop:

------------------
Rob Kapteyn

4. ## Re: Comparing two List of String

I believe the question was printing out the difference and not erroring out on a difference.

------------------

5. ## Re: Comparing two List of String

First confirm that the two lists have the same number of entries using the ListCount function and comparing the returned integer.

Then set up a for loop from 1 to the returned value from ListCount. Get the the same index from each list and use the Verify function within a do..except construct. If they match do nothing, if they do not print the first value, then the second value.

The following function handles this:

CheckLists(LIST OF STRING lsList1, LIST OF STRING lsList2)
INTEGER iCnt1
INTEGER iCnt2
INTEGER i

iCnt1 = ListCount (lsList1)
iCnt2 = ListCount (lsList2)

do
Verify (iCnt1, iCnt2)

except
Print("The two lists do not match in the number of entries")
Print("First list: {iCnt1} Second list {iCnt2}"
Print("")
return

for i = 1 to iCnt1
do
Verify (lsList1[i], lsList2[i])
except
Print("The following list values did not match")
Print("In list value {i}. List 1: {lsList1[i]} List 2: {lsList2[i]}")

------------------

6. ## Re: Comparing two List of String

Thanks everyone. This last one is really nice.
Thanks again..

------------------

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.