std::strspn

Header: <cstring>

Returns the length of the maximum initial segment (span) of the byte string pointed to by dest, that consists of only the characters found in byte string pointed to by src.

# Declarations

size_t strspn( const char* dest, const char* src );

# Parameters

# Return value

The length of the maximum initial segment that contains only characters from byte string pointed to by src.

# Example

#include <cstring>
#include <iostream>
#include <string>
 
const char* low_alpha = "qwertyuiopasdfghjklzxcvbnm";
 
int main()
{
    std::string s = "abcde312$#@";
 
    std::size_t spnsz = std::strspn(s.c_str(), low_alpha);
    std::cout << "After skipping initial lowercase letters from '" << s
              << "'\nThe remainder is '" << s.substr(spnsz) << "'\n";
}

# See also