在线文档教程
C++
字符串 | Strings

std::strcspn

STD::strcspn

Defined in header
size_t strcspn( const char *dest, const char *src

返回字节字符串的最大初始段的长度。dest,它仅由字符组成。指向的字节字符串中找到src...

函数名代表“互补跨度”。

参数

dest-pointer to the null-terminated byte string to be analyzed
src-pointer to the null-terminated byte string that contains the characters to search for

返回值

所指向的字节字符串中未找到的仅包含未找到字符的最大初始段的长度。src...

二次

#include <string> #include <cstring> #include <iostream> const char* invalid = "*$#"; int main() { std::string s = "abcde312$#@"; size_t valid_len = std::strcspn(s.c_str(), invalid if(valid_len != s.size()) std::cout << "'" << s << "' contains invalid chars starting at position " << valid_len << '\n'; }

二次

产出:

二次

'abcde312$#@' contains invalid chars starting at position 8

二次

另见

strspnreturns the length of the maximum initial segment that consists of only the characters found in another byte string (function)
wcscspnreturns the length of the maximum initial segment that consists of only the wide not found in another wide string (function)
strpbrkfinds the first location of any character from a set of separators (function)
find_first_offind first occurrence of characters (public member function of std::basic_string)

c strcspn的文档

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/string/字节/strcspn