C++ strspn() Function

C++ strspn()

The strspn() function finds up to what length two strings are identical.

This function is defined in <cstring> header file.

Example

C++ Compiler
#include <iostream> #include <cstring> using namespace std; int main() { char str1[] = "wikimass is awesome"; char str2[] = "wikipedia is great"; long len = strspn(str1, str2); cout << "Length of initial segment matching: " << len; return 0; }

Syntax

size_t strspn(const char *str1, const char *str2)

Parameter Values

ValueTypeExplanation
str1RequiredSpecifies the string 1
str2RequiredSpecifies the string 2

Return Value

ValueExplanation
Number Returns the position of the string from where the source array does not matches with the target one.

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.

Share this Page

Meet the Author