再给个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 */
str1.Contains(str2) str1.indexOf(str2)
注意,这个比较的说明: 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。
// 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
*/
str1.indexOf(str2)
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。
//包括在里边
else
//就不包括