这个 wcscspn() C/C++中的函数搜索 字符串2 在给定的范围内 字符串_1 。它返回第一次出现宽字符之前的宽字符数。搜索包括终止的空字符。因此,函数将返回 字符串_1 如果 字符串2 在 字符串_1 .
null
语法:
size_t wcscspn( const wchar_t* string_1, const wchar_t* string_2 )
参数: 该函数接受两个强制参数,如下所述:
- 字符串_1: 指定要搜索的字符串
- 字符串2: 指定包含要搜索的字符的字符串
返回值: 该函数返回两个值,如下所示:
- 它返回在字符串_1中第一次出现任何宽字符之前,字符串_2中的宽字符数。
- 如果在字符串_1中找不到字符串_2中的宽字符,则返回字符串_1的长度
以下程序说明了上述功能: 项目1:
// C++ program to illustrate // wcscspn() function #include <bits/stdc++.h> using namespace std; int main() { // string to be scanned wchar_t string_1[] = L "geeksforgeeks012345" ; // string containing the character to match wchar_t string_2[] = L "0123456789" ; // scanning the strings int last = wcscspn(string_1, string_2); // print the position of a matched character if (last > wcslen(string_1)) wcout << string_1 << L " Didn't match any character" ; else wcout << L "Occurrence of a character in -> " << string_1 << " is at position : " << last; return 0; } |
输出:
Occurrence of a character in -> geeksforgeeks012345 is at position : 13
项目2:
// C++ program to illustrate // wcscspn() function #include <bits/stdc++.h> using namespace std; int main() { // string to be scanned wchar_t string_1[] = L "GFG" ; // string containing the character to match wchar_t string_2[] = L "909090909" ; // scanning the strings int last = wcscspn(string_1, string_2); // print the position of a matched character if (last > wcslen(string_1)) wcout << string_1 << L " does not contain numbers" ; else wcout << L "Length of the string -> " << string_1 << " is : " << last; return 0; } |
输出:
Length of the string -> GFG is : 3
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END