std::strspn(3)
π
std::strspn π
okay so bestie, this is std::strspn(3) from the C++ Standard Libary manual, and it's giving βfind the longest opening chunk that only uses the characters you said were allowedβ energy. iconic behavior, honestly. π«Ά
β¨ NAME β¨
std::strspn β literally std::strspn, no cap. That's the name, periodt. π
πΈ Synopsis πΈ
Defined in header <cstring>.
size_t strspn( const char* dest, const char* src );
It 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 the byte string pointed to by src. like, it keeps looking at the start of dest and counts how many characters are all from src, and then it stops the second it sees a character that's not in src. π
π Parameters π
destβ pointer to the null-terminated byte string to be analyzed. this is the main character we're checking, bestie. πsrcβ pointer to the null-terminated byte string that contains the characters to search for. this is the VIP list of allowed characters. β¨
π¦ Return value π¦
The length of the maximum initial segment that contains only characters from the byte string pointed to by src. that's the count, and it's literally just the length of that allowed opening span. π―
π Example π
// Run this code
// Run this code
#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";
}
π Output: π
After skipping initial lowercase letters from 'abcde312$#@'
The remainder is '312$#@'
π₯ See also π₯
strcspnβ returns the length of the maximum initial segment that consists of only the characters not found in another byte string (function). the opposite vibe, lowkey. πwcsspnβ returns the length of the maximum initial segment that consists of only the wide characters found in another wide string (function). wide-character version, slay. πΈstrpbrkβ finds the first location of any character from a set of separators (function). it's giving βfirst matchβ energy. β- C documentation for
strspnβ yes bestie, the C docs forstrspnare right there too. π
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::strspn(3) β mwah, that's the footer, periodt. πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms