C++ strcspn() Function
You are Here:
C++ strcspn()
The strcspn()
function scans str1 for the first occurrence of any of the characters that are part of str2, returning index value of the first matched character.
This function is defined in <cstring> header file.
Example
C++ Compiler
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
long len;
char str1[] = "wikimass.com";
char str2[] = "msk";
// k is the first match
len = strcspn(str1, str2);
cout << "Index of first matched character: " << len;
return 0;
}
Output
Index of first matched character: 2
Syntax
size_t strcspn(const char *str1, const char *str2)
Parameter Values
Value | Type | Explanation |
---|---|---|
str1 | Required | Specifies the string 1 |
str2 | Required | Specifies the string 2 |
Return Value
Value | Explanation |
---|---|
Number | Returns the index value of the first matched character. |
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on C++ with examples for quick and easy learning.
We are working to cover every Single Concept in C++.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.