【C++】字符串操作
C API
strcat 是 C 语言标准库中的一个字符串操作函数,用于将一个字符串(源字符串)连接到另一个字符串(目标字符串)的末尾。它的函数原型如下:
char *strcat(char *dest, const char *src);
计算字符串中不包含指定字符集的前缀的长度
strcspn 是 C 语言中的一个字符串函数,用于计算字符串中不包含指定字符集的前缀的长度。
#include <stdio.h>
#include <string.h>int main() {const char *str1 = "Hello, World!";const char *str2 = "aeiou";size_t len = strcspn(str1, str2);printf("Length of the prefix not containing vowels: %zu\n", len);return 0;
}在这个例子中,strcspn 函数计算了字符串 "Hello, World!" 中不包含元音字母的前缀的长度。在这里,len 的值将是 2,因为前缀 "H" 和 "l" 都不包含在元音字母集合 "aeiou" 中。
