# Find matching characters in 2 strings

**URL:** <https://forum.cloverdx.com/t/find-matching-characters-in-2-strings/1784>\
**Category:** CloverDX Platform\
**Created:** [August 29, 2016, 12:00am UTC](https://forum.cloverdx.com/t/find-matching-characters-in-2-strings/1784 "2016-08-29T00:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggg\_123](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@ggg\_123](https://forum.cloverdx.com/u/ggg_123)\
**Post date:** [August 29, 2016, 12:00am UTC](https://forum.cloverdx.com/t/find-matching-characters-in-2-strings/1784/1 "2016-08-29T00:00:00Z")

</div>

Is there any way or in-built function in clover to find the matching characters in 2 strings.  
(ie) compare the contents of two strings and return a string containing characters that appear in both of them.  
**Eg:**  
If I have str1 = “AXBYCZ”, str2 = “ABCDEF”  
Then output should be = “ABC”

Also in similar lines if we compare 2 strings - if the first string content is same as the output then return TRUE.  
(ie)  
**Eg:**  
If I have str1 = “ABC”, str2 = “AXBYCDEF”  
Then output should be = 1

If I have str1 = “AXBYCZ”, str2 = “ABCDEF”  
Then output should be = 0

Is there any way or built-in function in Clover to acheive the above 2 tasks?

---

<div class="post-metadata">

**Author:** ![dpavlis](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dpavlis](https://forum.cloverdx.com/u/dpavlis)\
**Post date:** [August 30, 2016, 9:37am UTC](https://forum.cloverdx.com/t/find-matching-characters-in-2-strings/1784/2 "2016-08-30T09:37:17Z")

</div>

Hi,  
the first can be done somehow like this in CTL:

```auto
string str1;
string str2;
string target;

for(integer i=0;i<lenght(str1);i++){
string letter=charAt(str1,i);
if (contains(str2,letter) target=target+letter;
}

```

Basically I go through individual letters/characters of str1 and check whether they are included somewhere in str2. If yes then I add that letter to the target (result) string.

As for the other case - not sure what should be the logic. But you can use this example to deduce that piece of code you might need.
