使用字符串的IndexOf方法查找,找到返回正确的位置下标,未找到返回-1
举例:
string str = "我爱北京天安门";
int index = str.IndexOf("爱");
if (index > -1)
{
Console.Write("找到了");
}
else {
Console.Write("未找到");
}
Console.Read();
int baohan(char *s,char c)
{for(;*s;s++)
if(*s==c)return 1;
return 0;
}
调用方法:
char s[100]="Hello!";
char c='H'; //或 char c='h';
则
if(baohan(s,c))printf("%s 中包含字符 %c\n",s,c);
else ("%s 中不包含字符 %c\n",s,c);
一般开发语言里面都有这样的函数吧,你用的什么语言开发的,或者用正则也可以了,,