将两个字符串中相同的地方str2无重复的输出

str1 = "abcdefghijklmnopq";

str2 = "goodgoodxyz";

最简单的做法:

 public static string str1 = "abcdefghigklmnopqg",

str2 = "goodgoodxyz";

        public static int i, j,temp=0;

        static void Main(string[] args)

        {

            for(i=0;i<str2.Length;i++)//外边放str2

            {

                for(j=0;j<str1.Length;j++)

                {

                   

                    if (str2[i] == str1[j])

                    {

                        Console.Write(str2[i]);

                        break;//关键算法

                    }

                }

            }

            Console.ReadKey();

        }

 

原文地址:https://www.cnblogs.com/duoduo0605/p/2779122.html