// 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 */
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("字"); //查找“字”在str1中的索引值(位置)
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
str1.IndexOf("字",start,end);//从str1第start+1个字符起,查找end个字符,查找“字”在字符串STR1中的位置[从第一个字符算起]注 意:start+end不能大于str1的长度
string b ="in";
if (b.IndexOf(a)> -1)
{
有
}
else
{
没有
}