string str1 = "a,b,c"; string str2 = "a,b,c,d,e"; string[] arr1 = str1.Split(','); string[] arr2 = str2.Split(','); var tmp = from s in ((from s in arr1 select s).Distinct()).Concat((from s in arr2 select s).Distinct()) group s by s into g where g.Count() == 1 select g;
StringBuilder sb = new StringBuilder(); foreach (var s in tmp) { sb.AppendFormat("{0},", s.Key); } sb.Remove(sb.Length-1, 1); string result = sb.ToString();
string str2="a,b,c,d,e";
int j;
int a=0;
for(j=0;j<str2.lenth;j++)
{
for(int i=0;i<str1.lenth;i++)
{
a=0; \\标记
if(str1[i].Equals(str2[j]))
{
a=1;
break;
}
}
if(a=1)
{
Console.WriteLine(str2[j]);
}
} 必须知道那个字符串比较长
a=0在第一个循环内
改哈!
a=0在第一个循环内
改哈!
string str1 = "a,b,c";
string str2 = "a,b,c,d,e"; string[] arr1 = str1.Split(',');
string[] arr2 = str2.Split(','); var tmp = from s in ((from s in arr1 select s).Distinct()).Concat((from s in arr2 select s).Distinct())
group s by s into g
where g.Count() == 1
select g;
StringBuilder sb = new StringBuilder();
foreach (var s in tmp)
{
sb.AppendFormat("{0},", s.Key);
}
sb.Remove(sb.Length-1, 1); string result = sb.ToString();