找出一串字符串中不重复的字母;比如:"abbedeffygg"的输出结果为"ady"
string testString = "abbedeffygg";
//var filter = testString.ToCharArray().GroupBy(q => q).Where(q => q.Count() == 1).Select(q => q.Key);
//var result = string.Join("", filter.ToArray());
List<char> testList = testString.ToList<char>();
List<char> filter = testList;
for (int i = 0; i < testList.Count; i++)
{
for (int j = 0; j < testList.Count; j++)
{
if (i != j && testList[i] == testList[j])
{
// 找出重复字母
char delete = testList[i];
for (int k = 0; k < testList.Count; k++)
{
// 删除重复字母
if (testList.Contains(delete))
{
filter.Remove(delete);
}
}
}
}
}
var result = string.Join("", filter.ToArray());
Console.WriteLine(result);
Console.ReadKey();
本文来自博客园,作者:一纸年华,转载请注明原文链接:https://www.cnblogs.com/nullcodeworld/p/18210657