62,041
社区成员
发帖
与我相关
我的任务
分享
List<string> result = seq_l.Union(seq_r)
.Except(seq_l.Intersect(seq_r))
.ToList<string>();
void Main()
{
string s1 = "4, 3, 3, 56, 67, 4, 54, 56, 98, 56";
string s2 = "4,56,3,99";
var temp=s1.Split(',').Select(s=>s.Trim()).Distinct();
string result=string.Join(",",temp.Except(s2.Split(','))
.Union(s2.Split(',').Except(temp)).ToArray());
Console.WriteLine(result); //67,54,98,99
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s1 = "4, 3, 3, 56, 67, 4, 54, 56, 98, 56";
string s2 = "4,56,3,99";
var set1 = s1.Split(',').Select(x => x.Trim());
var set2 = s2.Split(',').Select(x => x.Trim());
var result = string.Join(",", set1.Union(set2).Except(set1.Intersect(set2)));
Console.WriteLine(result);
}
}
}
string lhs = "4,3,3,56,67,4,54,56,98,56";
string rhs = "4,56,3,99";
List<string> lt1 = lhs.Split(',').ToList().Distinct().ToList();
List<string> lt2 = rhs.Split(',').ToList().Distinct().ToList();
lt1.Except(lt2)
.Union(lt2.Except(lt1))
.ToList().ForEach(I => Response.Write(I.ToString() + "<br/>"));
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s1 = "4, 3, 3, 56, 67, 4, 54, 56, 98, 56";
string s2 = "4,56,3,99";
string result = string.Join(",", s1.Split(',').Select(x => x.Trim()).Where(x => !s2.Split(',').Select(y => y.Trim()).Any(y => y == x)).Union(s2.Split(',').Select(x => x.Trim()).Where(x => !s1.Split(',').Select(y => y.Trim()).Any(y => x == y))).Distinct());
Console.WriteLine(result);
}
}
}
string lhs = "4, 3, 3, 56, 67, 4, 54, 56, 98, 56";
string rhs = "4,56,3,99";
List<string> seq_l = lhs.Split(new char[] { ' ', ',' }).Select(s => s.Trim()).ToList<string>();
List<string> seq_r = rhs.Split(new char[] { ' ', ',' }).Select(s => s.Trim()).ToList<string>();
List<string> result = seq_l.Concat(seq_r)
.GroupBy(s => s)
.Where(g => g.Count() == 1)
.Select(r => r.Key)
.ToList<string>();
foreach (string s in result)
{
Console.WriteLine(s);
}
67
54
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s1 = "4, 3, 3, 56, 67, 4, 54, 56, 98, 56";
string s2 = "4,56,3,99";
string result = string.Join(",", s1.Split(',').Select(x => x.Trim()).Where(x => !s2.Split(',').Select(y => y.Trim()).Any(y => y == x)).Distinct());
Console.WriteLine(result);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s1 = "4, 3, 3, 56, 67, 4, 54, 56, 98, 56";
string s2 = "4,56,3,99";
string result = string.Join(", ", s1.Split(',').Select(x => x.Trim()).Where(x => !s2.Split(',').Select(y => y.Trim()).Any(y => y == x)).OrderBy(x => x).Distinct());
Console.WriteLine(result);
}
}
}