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

std::strspn

STD::strspn

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

返回指向的字节字符串的最大初始段%28 span%29的长度。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 <cstring> #include <string> #include <iostream> const char *low_alpha = "qwertyuiopasdfghjklzxcvbnm"; int main() { std::string s = "abcde312$#@"; std::size_t spnsz = std::strspn(s.c_str(), low_alpha std::cout << "After skipping initial lowercase letters from '" << s << "'\nThe remainder is '" << s.substr(spnsz) << "'\n"; }

二次

产出:

二次

After skipping initial lowercase letters from 'abcde312$#@' The remainder is '312$#@'

二次

另见

strcspnreturns the length of the maximum initial segment that consists of only the characters not found in another byte string (function)
wcsspnreturns the length of the maximum initial segment that consists of only the wide characters found in another wide string (function)
strpbrkfinds the first location of any character from a set of separators (function)

c strspn的文档

© cppreference.com

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

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