C中有没有找到子串重叠的函数?
在C中,是否有一个函数,当给定两个字符串时,将返回子字符串重叠或重叠的大小?就像这样做的那样:
char s1[5] = {cart};
char s2[4] = {car};
int overlap;
overlap = get_overlap(s1, s2); /*or have overlap be a string if it returns the overlap*.
然后重叠将为 3。
如果不是,我如何制作一个将返回重叠的 int 值的一个。
in C, is there a function that when giver two strings, will return the substring overlap or size of the overlap? So like something that does:
char s1[5] = {cart};
char s2[4] = {car};
int overlap;
overlap = get_overlap(s1, s2); /*or have overlap be a string if it returns the overlap*.
and then overlap would be 3.
If not, how do i make one that will return the int value of the overlap.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
strstr
。链接示例:输出:
注意:
整个子字符串将被匹配;请注意,
strstr
不进行部分匹配。Use
strstr
. Example from link:Output:
Note:
The entire substring will be matched ; note that
strstr
does not do partial matches.资格:该函数计算类型的重叠
在本例中,重叠为 3
Qualification: This function computed overlaps of the type
In this case, the overlap is 3
没有内置函数,但编写起来非常简单:
There's no builtin function, but it's pretty simple to write: