Last active
August 29, 2015 14:15
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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