# Find Substring of a String in Another String

Hi, I have two strings, 0017-Part and INV-0017 | P/O 9711,
I need to check if the second string contains any substring of the first string.

1 Like

Iβll assume str1 = β0017-Partβ and str2 = βINV-0017 | P/O 9711β

You can do this within an if activity, or an assign activity (result is a boolean): `str2.contains(str1)`

1 Like

Hi Dave,
so the thing is str2.contains(str1) will return false, but I need it to return true because 0017 is in both str1 and str2

Ok sorry I misunderstood. Do you have a predefined portion that you want to look at within str1? If not, you are going to find matches because str2 contains β0β,β1β,β7β,β-β,βPβ.

It seems like you want to match the β0017β portion though - is there a way that you can define how it will always appear? Is it always digits in the first part of the string? If so, you could use regex to pull out those digits only. Is it always going to be the first part preceding the β-β? If so, you could split the string by the β-β symbol, and take the first element in the array.

Either way, you want to determine how to pull out the substring from str1 that you actually want to search, then use that substring you pulled out to use the `str2.contains(str1substring)` formula