Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sotirisf/3877293fc6fd64b787dc to your computer and use it in GitHub Desktop.
Save sotirisf/3877293fc6fd64b787dc to your computer and use it in GitHub Desktop.
Compares two comma delimited strings in order to find at least one matching element (an element both strings contain)
/// <summary>
/// Compares two comma delimited strings in order to find at least one matching element
/// </summary>
/// <param name="sourceElements">The first comma delimited string</param>
/// <param name="searchElements">The second comma delimited string</param>
/// <returns>True if there is at least one match</returns>
public static bool MatchesAtLeastOne(this string sourceElements, string searchElements)
{
if (string.IsNullOrEmpty(sourceElements) || string.IsNullOrEmpty(searchElements)) return false;
bool retVal = false;
var searchArray = searchElements.Split(new Char[] { ',' });
var sourceArray = sourceElements.Split(new Char[] { ',' });
foreach (var s in searchArray)
{
foreach (var st in sourceArray)
{
if (st.Equals(s))
{
retVal = true;
break;
}
}
}
return (retVal);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment