var str1 = "ASD_ZIHJK2A";
\\ Output : pair 1 different character : Z
var str2 = "ASD_YIHJK2A";
\\ Output : pair 1 different character: Y
var str3 = "AWD_PIHJK2A";
\\ Output : pair 2 different character: P
var str4 = "AWD_IHJK2AQ";
\\ Output : pair 2 different character: Q
var str5 = "ASD_RTHJK2A";
\\ Output : pair 3 different character: J
var str6 = "ASD_RTHIK2A";
\Output : pair 3 difference : I
what is the simplest way to find the pairs and state difference for each string in the pair using C#?
-the strings to compare is in equal length
-string contain numbers in between as well
-position of the "different character" can different in the second string
Approach with Linq.Except
which
produces the set difference of two sequences. The set difference of two sets is defined as the members of the first set that don't appear in the second set.
This method returns those elements in first that don't appear in second. It doesn't return those elements in second that don't appear in first. Only unique elements are returned.
var strOne = "ASD_ZIHJK";
var strTwo = "ASD_YIHJK";
var difference_strOne = strOne.Except(strTwo); // Z
var difference_strTwo = strTwo.Except(strOne); // Y