Page 1 of 1

Compare two arrays

Posted: Wed Jun 05, 2019 11:59 am
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 ?

Re: Compare two arrays

Posted: Wed Jun 05, 2019 12:15 pm
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

Re: Compare two arrays

Posted: Wed Jun 05, 2019 2:39 pm
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
 

Re: Compare two arrays

Posted: Thu Jun 06, 2019 6:46 am
by Silvio.Falconi
nice
make some test