Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/byte/strspn"

From cppreference.com
< cpp‎ | string‎ | byte
 
m (langlinks)
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{cpp/title| strspn}}
+
{{cpp/title|strspn}}
{{cpp/string/narrow/sidebar}}
+
{{cpp/string/byte/navbar}}
{{ddcl | header=cstring |
+
{{ddcl|header=cstring|
size_t strspn( const char *dest, const char *src );
+
size_t strspn( const char* dest, const char* src );
 
}}
 
}}
  
Returns the length of the maximum initial segment of the character string pointed to by {{tt|dest}}, that consists of only the characters found in character string pointed to by {{tt|src}}.
+
Returns the length of the maximum initial segment (span) of the byte string pointed to by {{c|dest}}, that consists of only the characters found in byte string pointed to by {{c|src}}.
  
<!-- ======== -->
+
===Parameters===
{{params}}
+
{{par begin}}
{{param list begin}}
+
{{par|dest|pointer to the null-terminated byte string to be analyzed}}
{{param list item | dest | pointer to the null-terminated character string to be analyzed}}
+
{{par|src|pointer to the null-terminated byte string that contains the characters to search for}}
{{param list item | src | pointer to the null-terminated character string that contains the characters to search for}}
+
{{par end}}
{{param list end}}
+
  
<!-- ======== -->
+
===Return value===
{{returns}}
+
The length of the maximum initial segment that contains only characters from byte string pointed to by {{c|src}}.
  
the length of the maximum initial segment that contains only characters from character string pointed to by {{tt|src}}
+
===Example===
 +
{{example
 +
|code=
 +
#include <cstring>
 +
#include <iostream>
 +
#include <string>
  
<!-- ======== -->
+
const char* low_alpha = "qwertyuiopasdfghjklzxcvbnm";
{{example}}
+
 
{{example cpp
+
int main()
|
+
{
| code=
+
    std::string s = "abcde312$#@";
| output=
+
 
 +
    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===
{{see also}}
+
{{dsc begin}}
{{dcl list begin}}
+
{{dsc inc|cpp/string/byte/dsc strcspn}}
{{dcl list template | cpp/string/narrow/dcl list strcspn}}
+
{{dsc inc|cpp/string/wide/dsc wcsspn}}
{{dcl list template | cpp/string/narrow/dcl list strpbrk}}
+
{{dsc inc|cpp/string/byte/dsc strpbrk}}
{{dcl list end}}
+
{{dsc see c|c/string/byte/strspn}}
 +
{{dsc end}}
 +
 
 +
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 14:43, 6 June 2023

Defined in header <cstring>
size_t strspn( const char* dest, const char* src );

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.

Contents

[edit] Parameters

dest - pointer to the null-terminated byte string to be analyzed
src - pointer to the null-terminated byte string that contains the characters to search for

[edit] Return value

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

[edit] 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";
}

Output:

After skipping initial lowercase letters from 'abcde312$#@'
The remainder is '312$#@'

[edit] See also

returns the length of the maximum initial segment that consists
of only the characters not found in another byte string
(function) [edit]
returns the length of the maximum initial segment that consists
of only the wide characters found in another wide string
(function) [edit]
finds the first location of any character from a set of separators
(function) [edit]
C documentation for strspn