参加实训的第一天,要写一段小代码判定两个字符串是否包含,吃瘪了,写了一下午发现逻辑错误,然后到晚上有鼓捣了好久,才写出来,长时间不接触果然忘得差不多了,好歹完成了,留念一下
class Program
        {
                 public int text = 0;
                 static void Main( string[] args)
                {
                        Console.WriteLine( "第一个字符串");
                         string a = Console.ReadLine();
                        Console.WriteLine( "第二个字符串");
                         string b = Console.ReadLine();
                        Program d = new Program();
                        d.Mycontainer(a, b);
                         if (d.text == 1)
                        { Console.WriteLine( "包含"); }
                         else
                        { Console.WriteLine( "不包含"); }
                }
                 public void Mycontainer( string a, string b)
                {
                        CharEnumerator chara = a.GetEnumerator();
                        CharEnumerator charb = b.GetEnumerator();
                         for ( int i = 1; i <= a.Length - b.Length + 1; i++)
                        {
                                 for ( int k = 1; k < i; k++)
                                { chara.MoveNext(); }
                                 for ( int j = 1; j <= b.Length; j++)
                                {
                                        chara.MoveNext();
                                        charb.MoveNext();
                                         if (chara.Current.ToString() != charb.Current.ToString())
                                        { break; }
                                         if (chara.Current.ToString() == charb.Current.ToString() && j == b.Length)
                                        {
                                                text = 1;
                                        }
                                }
                                charb.Reset();
                                chara.Reset();
                        }

}
                }