// 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 */可以么?
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
label1.Text = textBox1.Text.IndexOf(textBox2.Text).ToString();
}
}
---------------------------------------
IndexOf找到返回位置,找不到返回-1
{
string t1 = "中华人民共和国";
string t2 = "华人";
if (t1.Contains(t2))
{
Console.WriteLine("yes");
}
else
{
Console.WriteLine("no");
}
}
运行结果:yes
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
*/可以么?
怎么我的C#里面String没有Contains这个函数?
我是在用C#写ASP.net程序。
using System.Text.RegularExpressions;
string m ="我的网站地址www.10000o.com.cn";
string n = Regex.Match(m, "地址www").ToString();
if (n != "")
{
//存在
}
else
{
//不存在
}
//验证通过
public ArrayList GetSearchItems( string strQuery )
{
//生成数据源
ArrayList items = new ArrayList();
items.Add("51aspx");
items.Add("aspx");
items.Add("asp.net");
items.Add("51aspx.com");
items.Add("51aspx51aspx");
items.Add("www.51aspx.com");
items.Add("aspx.net");
items.Add("中国人");
items.Add("中华人民共和国"); //筛选数据
ArrayList selectItems = new ArrayList();
foreach( string str in items )
{
string n = Regex.Match(str,strQuery).ToString();
if (n != "")
{
selectItems.Add(str);
}
}
return selectItems;
}