/*
The strstr() function finds the first occurrence of the substring needle
in the string haystack. The terminating '\0' characters are not compared.
*/
char *strstr_r(char *s1, char *s2)
{
/* s1 : hellwoleddlfjwo, s2: wol */
const char *p1, *p2;
if((*s2) == '\0') /* Early versions of Linux libc,strstr would not allow an empty needle argument */
return s1;
while( (s1 = strchr(s1, *s2)) != NULL) {
p1 = s1; /* found first character of s2, see if the rest matches */
p2 = s2;
while((*p1++ == *p2++)) {
if(*p1 == '\0')
return s1; /* both strings ended together */
}
if(*p2 == '\0') {
break;
}
s1++;
}
return s1;
}
分享到:
相关推荐
C strstr字符串查找函数优化,解决查找中文汉字匹配存在错误BUG问题。支持GBK、GB18030字符串。
字符串相关函数介绍,strchr ,strstr,strtok
主要介绍了php常用字符串查找函数strstr()与strpos(),结合具体实例形式分析了php字符串查找函数strstr()与strpos()的具体功能、用法、区别及相关操作注意事项,需要的朋友可以参考下
参考字符串函数,有strstr strcat strcpy strcmp等
这些是常用的字符串操作函数,有些和C中的同名函数意义完全一致. strrev是把一个字符串翻转. strtolower和strtoupper的意思应该不用解释了. ucfirst是把字符串的第一个字符变成大写. substr是返回字符串的一个...
php字符串函数学习之strstr()_.docx
C语言字符串函数的实现,strlen、strcpy、strstr、srtcat等
该程序是我写的博客“一起talk C栗子吧(第六十三回:C语言实例--字符串查找)”的配套程序,共享给大家使用
要按字节顺序进行字符串的比较,可以使用strcmp()和strcasecmp()两个函数,其中函数strcasecmp()可以忽略字符串中字母的大小写进行比较。这两个函数的原型如下所示: 复制代码 代码如下: in strcmp(string str1,...
strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。 该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。 语法 string strstr ( string, search) 参数 描述 string 必需...
通过函数 strstr() ,找到 字符串第一次出现的位置。打印出此字符串之前与之后的字符串
strcpy,strncpy,strcat,strncat,strcmp,strncmp,strchr,strnchr,strlen,strnlen,strspn,strpbrk,strtok,strsep,memset,bcopy,memcpy,memmove,memcmp,memscan,...函数具体实现内容。对理解C语言和C编程有很大帮助。
主要介绍 strcpy(),strncpy(), strcat(), strncat(), strcmp(), strncmp(), strchar(), strrchr(), strspn(), strcspn(), strpbrk(), strstr(), strlen(), strerror(), strtok()等。
C语言字符串操作的8个库函数源代码 1.strcpy.c 2.strcat.c 3.strlen.c 4.Insstr.c 5.substr.c 6.strstr.c 7.delstr.c 8.strcmp.c
对 stdlib 的strstr()子字符串搜索函数的快速替换。 在搜索相对较小的子字符串(例如单词fast_strstr()比大多数子字符串搜索算法要快得多。 我们建议任何用户在他们的数据上对算法进行基准测试,因为它使用与...
C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 ...strstr 在字符串str1中定位字符串str2首次出现的位置 函数说明: 1、memchr 原型:const void * me
strstr 定义和用法 ...如果设置为 “true”,它将返回 search 参数第一次出现之前的字符串部分。 技术细节 返回值: 返回字符串的剩余部分(从匹配点)。如果未找到所搜索的字符串,则返回 FALSE。 P
1、查找字符位置函数: strpos($str,search,[int])://查找search在$str中的第一次位置从...strstr($str1,$str2)://从$str1(第一个的位置)搜索$str2并从它开始截取到结束字符串;若没有则返回FALSE。 stristr()//功能同