- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于 AIX 中的 gcc 编译器,我们是否有替代 strrspn 和 strfind 函数(Solaris 中的 libgen 函数)的替代方案?
下面提到了这些功能 -
int strfind(const char *s1, const char *s2);
- The strfind() function returns the offset of the first occurrence of the second string, s2, if it is a substring of string s1. If the second string is not a substring of the first string strfind() returns -1.
char *strrspn(const char *string, const char *cset);
- The strrspn() function trims chartacters from a string. It searches from the end of string for the first character that is not contained in cset. If such a character is found, strrspn() returns a pointer to the next character; otherwise, it returns a pointer to string.
请帮忙解决这个问题吗?
最佳答案
据我所知,没有什么与 strfind
完全一样的。但你可以使用 strstr
来实现它:
int
strfind (const char *haystack, const char *needle)
{
const char *res = strstr(haystack, needle);
// if not found, return -1
if (res == NULL)
return -1;
// else return the offset in haystack
return res - haystack;
}
strrspn
可能有点棘手,但你可以按照以下方式做一些事情:
char*
strrspn (const char *string, const char *cset)
{
size_t len = strlen(strign);
const char *p = string + len;
// start from the back, and look for a char not in cset
while (--p >= string)
if (NULL == strchr(cset, *p))
return p;
return string
}
不用说,这些功能完全未经测试,并且可能无法正常工作,但它们应该可以给您一个想法。
关于c - AIX 中 strrspn 和 strfind 函数(Solaris 中的 libgen 函数)的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30728443/
我有一个 1x5 的单元格,它看起来像这样: A = {'asd','pqr','asd 123','pqr123','asd 1','dfg',} 当我这样做时: strfind(A,'asd')
我想在 strfind 函数上使用 cellfun 函数来查找另一个字符串元胞数组中字符串元胞数组中每个字符串的索引,以将它们从中排除. strings = {'aaa','bbb','ccc','d
问题:我有两个大型字符串元胞数组A 和B。我想知道识别 A 中哪些元素包含 B 中哪些元素的最快方法。特别是不循环能不能做到? 最小示例:(我的实际 A 和 B 分别包含 7,000,000 和 22
出于某种原因 size(strfind(n,',')) 数字 44 很特殊,会产生逗号查找结果: value={55} numCommas = size(strfind(value{1},','),2
对于 AIX 中的 gcc 编译器,我们是否有替代 strrspn 和 strfind 函数(Solaris 中的 libgen 函数)的替代方案? 下面提到了这些功能 - int strfind(c
我是一名优秀的程序员,十分优秀!