wuruoyu 2 Posted September 28, 2019 (edited) Tried searching through the forum and can't seem to find a way do this want compare 2 strings, they both have common values and unique values, and generate 3 seperate arrays 1st string/array = all common and unique values (1,2,3,4) 2nd string/array = booleans that indicate values that have found in string1 (Y,Y,Y,N) 3rd string/array = booleans that indicate values that have found in string2 (N,Y,Y,Y) E.g. string1 = "1,2,3" string2 = "2,3,4" str string1 string2 1 Y N 2 Y Y 3 Y Y 4 N Y Thank you in advance! Edited September 28, 2019 by wuruoyu Share this post Link to post Share on other sites
TheXman 405 Posted September 29, 2019 (edited) You can use the _ArrayAdd or _ArrayConcatenate funtions to combine array1 and array2 into a single array. You can then use the _ArrayUnique function to remove duplicates. Then it is just a matter of spinning through the array of unique values and comparing those value to the values in array 1 & 2. #include <Constants.au3> #include <Array.au3> example() Func example() Const $A1 = [1,2,3], _ $A2 = [2,3,4] Local $aUniqueItems[0], _ $aBool1[0], _ $aBool2[0] ;Combine array 1 & 2 _ArrayAdd($aUniqueItems, $A1) _ArrayAdd($aUniqueItems, $A2) ;Remove duplicates and sort $aUniqueItems = _ArrayUnique($aUniqueItems, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) _ArraySort($aUniqueItems) ;Build boolean result arrays For $i = 0 To UBound($aUniqueItems) - 1 _ArrayAdd($aBool1, (_ArraySearch($A1, $aUniqueItems[$i]) > -1 ? "Y" : "N")) _ArrayAdd($aBool2, (_ArraySearch($A2, $aUniqueItems[$i]) > -1 ? "Y" : "N")) Next ;Show results _ArrayDisplay($aUniqueItems, "Unique Items") _ArrayDisplay($aBool1, "String 1") _ArrayDisplay($aBool2, "String 2") EndFunc Edited September 29, 2019 by TheXman About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
wuruoyu 2 Posted September 29, 2019 14 minutes ago, TheXman said: You can use the _ArrayAdd or _ArrayConcatenate funtions to combine array1 and array2 into a single array. You can then use the _ArrayUnique function to remove duplicates. Then it is just a matter of spinning through the array of unique values and comparing those value to the values in array 1 & 2. #include <Constants.au3> #include <Array.au3> example() Func example() Const $A1 = [1,2,3], _ $A2 = [2,3,4] Local $aUniqueItems[0], _ $aBool1[0], _ $aBool2[0] ;Combine array 1 & 2 _ArrayAdd($aUniqueItems, $A1) _ArrayAdd($aUniqueItems, $A2) ;Remove duplicates and sort $aUniqueItems = _ArrayUnique($aUniqueItems, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) _ArraySort($aUniqueItems) ;Build boolean result arrays For $i = 0 To UBound($aUniqueItems) - 1 _ArrayAdd($aBool1, (_ArraySearch($A1, $aUniqueItems[$i]) > -1 ? "Y" : "N")) _ArrayAdd($aBool2, (_ArraySearch($A2, $aUniqueItems[$i]) > -1 ? "Y" : "N")) Next ;Show results _ArrayDisplay($aUniqueItems, "Unique Items") _ArrayDisplay($aBool1, "String 1") _ArrayDisplay($aBool2, "String 2") EndFunc Genius! Thanks TheXman Share this post Link to post Share on other sites
TheXman 405 Posted September 29, 2019 You're welcome! About TheXman | CryptoNG UDF - Cryptography API: Next Gen | HttpApi UDF - HTTP Server API | jq UDF - Powerful and Flexible JSON Processor Share this post Link to post Share on other sites
Chimp 715 Posted September 29, 2019 (edited) ... here my 2 cents, (string functions based) #include <Array.au3> Local $string1 = "1,2,3,4" Local $string2 = "2,3,4" ; merge the 2 strings and place elements in an array Local $aAll = StringSplit($string1 & ',' & $string2, ',', 2) ; keep only unique values Local $aUnique = _ArrayUnique($aAll) ; , 0, 0, 0, 0) ; create an empty array to store results (with headers) Local $aResult[UBound($aUnique)][3] = [['values', 'in str1', 'in str2']] ; check presence of values in $string1 and $string2 For $i = 1 To UBound($aUnique) - 1 ; print result on console ConsoleWrite($aUnique[$i] & @TAB & (StringInStr($string1, $aUnique[$i]) = True) & @TAB & (StringInStr($string2, $aUnique[$i]) = True) & @CRLF) ; store results in array $aResult[$i][0] = $aUnique[$i] $aResult[$i][1] = StringInStr($string1, $aUnique[$i]) = True $aResult[$i][2] = StringInStr($string2, $aUnique[$i]) = True Next ; display result _ArrayDisplay($aResult) Edited September 29, 2019 by Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites