我有一个string str1="2008110601";
       string str2="20081106";
我就是判断str1是否相似于str2 ?
就是str1中有没有str2   ?大哥们帮帮忙吧。

解决方案 »

  1.   

    再给个MSDN的例子,完美。
    // This example demonstrates the String.Contains() method
    using System;class Sample 
    {
        public static void Main() 
        {
        string s1 = "The quick brown fox jumps over the lazy dog";
        string s2 = "fox";
        bool b;
        b = s1.Contains(s2);
        Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
        }
    }
    /*
    This example produces the following results:Is the string, s2, in the string, s1?: True
    */
      

  2.   

    str1.Contains(str2)
    str1.indexOf(str2)
      

  3.   

    注意,这个比较的说明:
    This method performs an ordinal (case-sensitive and culture-insensitive) comparison. The search begins at the first character position of this string and continues through the last character position.这表示它的操作是大小写敏感的。对于上面MSDN中给出的例子,如果s2不是fox而是Fox,FOX之类的,将返回false。
      

  4.   

     if (str2.indexof(str1)<>-1)
       //包括在里边
    else
      //就不包括