Compare two arrays

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Compare two arrays

Post by Silvio.Falconi »

can you compare two arrays to see if there are equal elements?

for example:

in an array I have

"AAAAA","BBBBB","CCCCC"
"AAAAA","BBBBB","CCCCC"
"BBBBB","BBBBB","BBBBBB"

on another I have

"AAAAA","BBBBB","CCCCC"
"AAAAA","BBBBB","CCCCC"
"AAAAA","BBBBB","CCCCC"


is there a function that lets you know that the line "AAAAA", "BBBBB", "CCCCC" is present in the other array?


I need this operation because at the time the beach structure is built, the program automatically recognizes the areas where the umbrellas are located and creates a base rate: it could happen that the operator has already entered some tariffs for the same sector or has entered some tariffs for a sector that in the modification structure does not exist or there is no given element

the user could cancel all the tariffs and insert new ones from scratch or the procedure could make a check and see if there are records that have some equal fields
IDLISTINO | IDELEMENTO | FIELD | DAYS

for a sample

Image

on up there is a new array calculated
down there is the array with oldest tariffs

the check must be made by idlistino,idelemento, giorni,idsettore

How I can resolve it ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Compare two arrays

Post by ukoenig »

Silvio,

the new release FWH 19.05 offers new functions
Additional features:

cSearch can be a string or array of strings. In case of array, the earliest occurance
is reported.

If lWholeWord is .t., only whole words are matched.
Eg: FW_ATI( "EAR", "Years Hear Ear", nil, nil, .T. ) --> 12, but not 2.

If lSkipQuotes is .t., the search skips any text inside quotes, "...", '...' or [...]
Eg: FW_ATI( "NEAR", 'He said "it is near" but it is not near', nil, nil, nil, .t. )
--> 36 but not 16

If @cFound is specified as 7th parameter by reference, the exact match found in the
string is returned. Eg: In the above case it returns "near".

If cReplace is specified as 8th parameter and cString is by reference, cFound is
replaced by cReplace.

It the 9th parameter lAll is set to .T., all matches are returned as Array. In case of
cReplace, all occurances are replaced by cReplace.

- New function FW_STRICMP(): Compares the two strings ignoring the case.
Respect SET EXACT off/on setting, subject to override

Usage1: FW_StrICmp( cStr1, cStr2, [lExact] ) --> -1,0,+1 for less than,
equal or greater than. 3rd parameter, if specified, overrides SET EXACT
setting

Usage2: FW_StrICmp( cStr1, cCompOperator, cStr2, [lExact] ) --> .f. / .t.
Eg: FW_StrICmp( c1, ">=", c2, [nil,.t.,.f.] ) --> .t./.f.
Operator "==" forces exact comparison. In other cases 4th paramter specifies
if comparision is exact and if omitted, default setting is used.
regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Compare two arrays

Post by nageswaragunupudi »

Code: Select all

function SearchArray( aSearch, aArray )

   local n

   for n := 1 to Len ( aArray )
      if aSearch[ 1 ] == aArray[ n, 1 ] .and. ;
         aSearch[ 2 ] == aArray[ n, 2 ] .and. ;
         aSearch[ 3 ] == aArray[ n, 3 ]

         return n
      endif
   next

return 0
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Compare two arrays

Post by Silvio.Falconi »

nice
make some test
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply