strspn_C语言中文网
| 定义于头文件 |
||
| size_t strspn( const char *dest, const char *src ); |
||
返回 dest 所指向的空终止字节串的最大起始段( span )长度,段仅由 src 所指向的空终止字节字符串中找到的字符组成。
若 dest 或 src 不是指向空终止字节字符串的指针,则行为未定义。
参数
| dest | - | 指向要分析的空终止字节字符串的指针 |
| src | - | 指向含有要搜索的字符的空终止字节字符串的指针 |
返回值
仅由来自 src 所指向的空终止字节字符串的字符组成的最大起始段长度。
示例
#include <string.h> #include <stdio.h> int main(void) { const char *string = "abcde312$#@"; const char *low_alpha = "qwertyuiopasdfghjklzxcvbnm"; size_t spnsz = strspn(string, low_alpha); printf("After skipping initial lowercase letters from '%s'\n" "The remainder is '%s'\n", string, string+spnsz); }
输出:
After skipping initial lowercase letters from 'abcde312$#@' The remainder is '312$#@'
引用
- C11 standard (ISO/IEC 9899:2011):
- 7.24.5.6 The strspn function (p: 369)
- C99 standard (ISO/IEC 9899:1999):
- 7.21.5.6 The strspn function (p: 332)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.11.5.6 The strspn function
参阅
| 返回另一个字符串所不具有的字符分割的最大起始段长度 (函数) | |
| 返回仅由另一个宽字符串中出现的宽字符分隔的最长首段长度 (函数) | |
| 查找一个字符串中的任意一个字符在另一个字符串中的首个位置 (函数) |