std::strspn
来自cppreference.com
| 在标头 <cstring> 定义
|
||
| |
||
返回 dest 所指向的空终止字节串的最大起始段(span)长度,段仅由 src 所指向的空终止字节字符串中找到的字符组成。
参数
| dest | - | 指向要分析的空终止字节字符串的指针 |
| src | - | 指向含有要搜索的字符的空终止字节字符串的指针 |
返回值
仅由来自 src 所指向的空终止字节字符串的字符组成的最大起始段长度。
示例
运行此代码
#include <cstring>
#include <iostream>
#include <string>
const char* low_alpha = "qwertyuiopasdfghjklzxcvbnm";
int main()
{
std::string s = "abcde312$#@";
std::size_t spnsz = std::strspn(s.c_str(), low_alpha);
std::cout << "跳过 '" << s << "' 的初始小写字母后\n"
<< "剩余 '" << s.substr(spnsz) << "'\n";
}
输出:
跳过 'abcde312$#@' 的初始小写字母后
剩余 '312$#@'
