找出一串字符串中不重复的字母;比如:"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();
posted @ 2020-05-24 11:01  一纸年华  阅读(6)  评论(0编辑  收藏  举报  来源