wuruoyu Posted September 28, 2019 Share 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 Link to comment Share on other sites More sharing options...
TheXman Posted September 29, 2019 Share 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 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
wuruoyu Posted September 29, 2019 Author Share 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 Link to comment Share on other sites More sharing options...
TheXman Posted September 29, 2019 Share Posted September 29, 2019 You're welcome! CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Gianni Posted September 29, 2019 Share 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now