Difference between revisions of "cpp/string/byte"
From cppreference.com
(improve explanation) |
m (→First statement: add note that in NTBS a byte sequence before terminator might be empty.) |
||
(23 intermediate revisions by 10 users not shown) | |||
Line 1: | Line 1: | ||
− | {{title| | + | {{title|Null-terminated byte strings}} |
− | {{cpp/string/ | + | {{cpp/string/byte/navbar}} |
− | A null-terminated | + | A null-terminated byte string (NTBS) is a possibly empty sequence of nonzero bytes followed by a byte with value zero (the terminating null character). Each byte in a byte string encodes one character of some character set. For example, the character array {{c|{'\x63', '\x61', '\x74', '\0'}<!---->}} is an NTBS holding the string {{c|"cat"}} in ASCII encoding. |
− | + | ===Functions=== | |
+ | {{dsc begin}} | ||
+ | {{dsc h2|Character classification}} | ||
+ | {{dsc header|cctype}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isalnum}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isalpha}} | ||
+ | {{dsc inc|cpp/string/byte/dsc islower}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isupper}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isdigit}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isxdigit}} | ||
+ | {{dsc inc|cpp/string/byte/dsc iscntrl}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isgraph}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isspace}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isblank}} | ||
+ | {{dsc inc|cpp/string/byte/dsc isprint}} | ||
+ | {{dsc inc|cpp/string/byte/dsc ispunct}} | ||
− | {{ | + | {{dsc h2|Character manipulation}} |
+ | {{dsc inc|cpp/string/byte/dsc tolower}} | ||
+ | {{dsc inc|cpp/string/byte/dsc toupper}} | ||
+ | {{dsc end}} | ||
+ | {{cpp/string/character classes}} | ||
+ | {{dsc begin}} | ||
− | {{ | + | {{dsc h2|Conversions to numeric formats}} |
− | {{ | + | {{dsc header|cstdlib}} |
+ | {{dsc inc|cpp/string/byte/dsc atof}} | ||
+ | {{dsc inc|cpp/string/byte/dsc atoi}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strtol}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strtoul}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strtof}} | ||
+ | {{dsc header|cinttypes}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strtoimax}} | ||
− | {{ | + | {{dsc h2|String manipulation}} |
− | {{ | + | {{dsc header|cstring}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strcpy}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strncpy}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strcat}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strncat}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strxfrm}} |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | {{ | + | {{dsc h2|String examination}} |
− | {{ | + | {{dsc header|cstring}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strlen}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strcmp}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strncmp}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strcoll}} |
+ | {{dsc inc|cpp/string/byte/dsc strchr}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strrchr}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strspn}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strcspn}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strpbrk}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strstr}} | ||
+ | {{dsc inc|cpp/string/byte/dsc strtok}} | ||
− | {{ | + | {{dsc h2|Character array functions}} |
− | {{ | + | {{dsc header|cstring}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc memchr}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc memcmp}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc memset}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc memcpy}} |
+ | {{dsc inc|cpp/string/byte/dsc memmove}} | ||
− | {{ | + | {{dsc h2|Miscellaneous}} |
− | {{ | + | {{dsc header|cstring}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strerror}} |
− | {{ | + | {{dsc end}} |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | {{ | + | ===See also=== |
− | {{ | + | {{dsc begin}} |
− | + | {{dsc see c|c/string/byte|{{tt|Null}}-terminated byte strings|nomono=true}} | |
− | {{ | + | {{dsc end}} |
− | + | ||
− | {{ | + | |
− | {{ | + | {{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|zh}} |
− | + | ||
− | + |
Latest revision as of 14:28, 21 February 2023
A null-terminated byte string (NTBS) is a possibly empty sequence of nonzero bytes followed by a byte with value zero (the terminating null character). Each byte in a byte string encodes one character of some character set. For example, the character array {'\x63', '\x61', '\x74', '\0'} is an NTBS holding the string "cat" in ASCII encoding.
Contents |
[edit] Functions
Character classification | |
Defined in header
<cctype> | |
checks if a character is alphanumeric (function) | |
checks if a character is alphabetic (function) | |
checks if a character is lowercase (function) | |
checks if a character is an uppercase character (function) | |
checks if a character is a digit (function) | |
checks if a character is a hexadecimal character (function) | |
checks if a character is a control character (function) | |
checks if a character is a graphical character (function) | |
checks if a character is a space character (function) | |
(C++11) |
checks if a character is a blank character (function) |
checks if a character is a printing character (function) | |
checks if a character is a punctuation character (function) | |
Character manipulation | |
converts a character to lowercase (function) | |
converts a character to uppercase (function) |
ASCII values | characters | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
decimal | hexadecimal | octal | |||||||||||||
0–8 | \x0 –\x8
|
\0 –\10
|
control codes (NUL , etc.)
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
9 | \x9
|
\11
|
tab (\t )
|
≠0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
10–13 | \xA –\xD
|
\12 –\15
|
whitespaces (\n , \v , \f , \r )
|
≠0
|
0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
14–31 | \xE –\x1F
|
\16 –\37
|
control codes | ≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
32 | \x20
|
\40
|
space | 0
|
≠0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
33–47 | \x21 –\x2F
|
\41 –\57
|
!"#$%&'()*+,-./
|
0
|
≠0
|
0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
48–57 | \x30 –\x39
|
\60 –\71
|
0123456789
|
0
|
≠0
|
0
|
0
|
≠0
|
0
|
≠0
|
0
|
0
|
0
|
≠0
|
≠0
|
58–64 | \x3A –\x40
|
\72 –\100
|
:;<=>?@
|
0
|
≠0
|
0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
65–70 | \x41 –\x46
|
\101 –\106
|
ABCDEF
|
0
|
≠0
|
0
|
0
|
≠0
|
0
|
≠0
|
≠0
|
≠0
|
0
|
0
|
≠0
|
71–90 | \x47 –\x5A
|
\107 –\132
|
GHIJKLMNOP QRSTUVWXYZ
|
0
|
≠0
|
0
|
0
|
≠0
|
0
|
≠0
|
≠0
|
≠0
|
0
|
0
|
0
|
91–96 | \x5B –\x60
|
\133 –\140
|
[\]^_`
|
0
|
≠0
|
0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
97–102 | \x61 –\x66
|
\141 –\146
|
abcdef
|
0
|
≠0
|
0
|
0
|
≠0
|
0
|
≠0
|
≠0
|
0
|
≠0
|
0
|
≠0
|
103–122 | \x67 –\x7A
|
\147 –\172
|
ghijklmnop qrstuvwxyz
|
0
|
≠0
|
0
|
0
|
≠0
|
0
|
≠0
|
≠0
|
0
|
≠0
|
0
|
0
|
123–126 | \x7B –\x7E
|
\172 –\176
|
{|}~
|
0
|
≠0
|
0
|
0
|
≠0
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
127 | \x7F
|
\177
|
backspace character (DEL )
|
≠0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
Conversions to numeric formats | |
Defined in header
<cstdlib> | |
converts a byte string to a floating point value (function) | |
(C++11) |
converts a byte string to an integer value (function) |
(C++11) |
converts a byte string to an integer value (function) |
(C++11) |
converts a byte string to an unsigned integer value (function) |
converts a byte string to a floating-point value (function) | |
Defined in header
<cinttypes> | |
(C++11)(C++11) |
converts a byte string to std::intmax_t or std::uintmax_t (function) |
String manipulation | |
Defined in header
<cstring> | |
copies one string to another (function) | |
copies a certain amount of characters from one string to another (function) | |
concatenates two strings (function) | |
concatenates a certain amount of characters of two strings (function) | |
transform a string so that strcmp would produce the same result as strcoll (function) | |
String examination | |
Defined in header
<cstring> | |
returns the length of a given string (function) | |
compares two strings (function) | |
compares a certain number of characters from two strings (function) | |
compares two strings in accordance to the current locale (function) | |
finds the first occurrence of a character (function) | |
finds the last occurrence of a character (function) | |
returns the length of the maximum initial segment that consists of only the characters found in another byte string (function) | |
returns the length of the maximum initial segment that consists of only the characters not found in another byte string (function) | |
finds the first location of any character from a set of separators (function) | |
finds the first occurrence of a substring of characters (function) | |
finds the next token in a byte string (function) | |
Character array functions | |
Defined in header
<cstring> | |
searches an array for the first occurrence of a character (function) | |
compares two buffers (function) | |
fills a buffer with a character (function) | |
copies one buffer to another (function) | |
moves one buffer to another (function) | |
Miscellaneous | |
Defined in header
<cstring> | |
returns a text version of a given error code (function) |
[edit] See also
C documentation for
Null -terminated byte strings |