字符串查找 [英] string finding
问题描述
大家好,
我很想知道字符串函数,(用户自定义)。告诉我
在另一个字符串中查找字符串的技巧。
Hello everyone,
I am eager to know about string functions, (user defined) . tell me
the technique of find a string in another string.
推荐答案
你看过strcmp吗?和strncmp?
如果你想自己编写,你可以使用for循环继续查看
的第一个char,当找到时,寻找第二辆车。
John Dirk
编程顾问
http://www.programminghelp4u.com - 编程(作业/项目)帮助
Have you looked into strcmp and strncmp?
IF you want to write your own, u could use a for loop and keep on looking
for the first char and when that found, look for the second car.
John Dirk
Programming Consulant
http://www.programminghelp4u.com - Programming (Assignment/Project) Help
ne*****@gmail.com 写道:
大家好,
我渴望了解字符串函数(用户定义)。告诉我
在另一个字符串中查找字符串的技巧。
Hello everyone,
I am eager to know about string functions, (user defined) . tell me
the technique of find a string in another string.
#include< string.h>
char * str_str(const char * s1,const char * s2)
{
const int c = * s2 ++;
if(c!=''\'''){
const size_t n = strlen(s2);
s1 = strchr(s1 ,c);
while(s1!= NULL&& strncmp(s1 + 1,s2,n)!= 0){
s1 = strchr(s1 + 1,c);
}
}
return(char *)s1;
}
-
pete
#include <string.h>
char *str_str(const char *s1, const char *s2)
{
const int c = *s2++;
if (c != ''\0'') {
const size_t n = strlen(s2);
s1 = strchr(s1, c);
while (s1 != NULL && strncmp(s1 + 1, s2, n) != 0) {
s1 = strchr(s1 + 1, c);
}
}
return (char *)s1;
}
--
pete
proghelper写道:
proghelper wrote:
你看过吗进入strcmp和strncmp?
如果你想自己编写,你可以使用for循环继续查看
Have you looked into strcmp and strncmp?
IF you want to write your own, u could use a for loop and keep on looking
请不要不要使用缩写链接u。这使你更难阅读你的
帖子并让你看起来很愚蠢。
请始终引用足够的原帖以提供上下文
Usenet的工作方式意味着人们可能不会,而且确实可能从未b
,看到你回复的消息。
-
Flash Gordon
生活在有趣的时代。
虽然我的电子邮件地址说垃圾邮件,但这是真实的,我读了它。
Please don''t use abbreviations link "u". It makes it harder to read your
posts and makes you look stupid.
Please always quote enough of the original post to provide context since
the way Usenet works means that people might not, and indeed may
never, see the message you are replying to.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
这篇关于字符串查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!