- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何计算 strspn
函数中提到的值以外的值的数量?我知道 strspn
计算参数 2 中提到的字符的总出现次数,但我想做相反的事情。
例如,如果我有字符串:ABCDEFGH
我想统计D
以外的字符数。所以答案是:7
。
无论如何我可以用 strspn
做到这一点吗?
最佳答案
你想计算总个不匹配集合的字符,你需要自己实现这个函数,用一个循环:
size_t count_non_matching_chars(const char *str, const char *set) {
size_t pos = 0, count = 0, chunk;
while (str[pos] != '\0') {
pos += strspn(str + pos, set); /* skip the matching chars */
chunk = strcspn(str + pos, set); /* count non matching chars */
pos += chunk;
count += chunk;
}
return count;
}
这是一个只使用 strspn()
的替代方案,如果有很多不匹配的字符,效率会稍微低一些:
size_t count_non_matching_chars(const char *str, const char *set) {
size_t pos = 0, count = 0;
for (;;) {
pos += strspn(str + pos, set); /* skip the matching chars */
if (str[pos] == '\0')
break;
count++; /* count and skip the non-matching character */
pos++;
}
return count;
}
关于c - 如何使用strspn查找strspn的arg 2中提到的字符数以外的字符数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35367210/
client.on('message', message => { if (message.content === `L!hug`) { if (!message.menti
我往往会忘记我 stash 了一些更改。当存储空间不为空时,我希望看到 git status 输出中提到的存储空间。有没有办法让 git status 这样做? 最佳答案 This is now a
[object Object] 是 JavaScript 对象的默认字符串表示。 如果只是 [Object] 或 [object] 我会理解,但为什么是 [object Object]?为什么第一个单
Jython 可以在这里提供帮助吗?我应该在 Jython 之上运行 Grails,如果是,如何运行?不知何故,我应该能够在同一个 JVM 上运行 Grails 和 Python 脚本。还有其他可能性
http://download.oracle.com/javase/tutorial/collections/interfaces/set.html 为什么Set接口(interface)会列出Col
我正在使用 keras 编写一个 ner 模型,并将模型部署到tensorflow-serving。然后使用http请求来获取预测结果。 这是我的代码: EMBEDDING_OUT_DIM = 128
我是一名优秀的程序员,十分优秀!