Difference between revisions of "cpp/string/byte/strrchr"
From cppreference.com
m (r2.7.3) (Robot: Adding de, es, it, pt, ru) |
m (langlinks) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/title| strrchr}} | + | {{cpp/title|strrchr}} |
{{cpp/string/byte/navbar}} | {{cpp/string/byte/navbar}} | ||
− | {{ | + | {{dcl begin}} |
− | {{ | + | {{dcl header|cstring}} |
− | {{ | + | {{dcl| |
− | const char *strrchr( const char *str, int ch ); | + | const char* strrchr( const char* str, int ch ); |
}} | }} | ||
− | {{ | + | {{dcl|1= |
− | char *strrchr( char *str, int ch ); | + | char* strrchr( char* str, int ch ); |
}} | }} | ||
− | {{ | + | {{dcl end}} |
− | Finds the last occurrence of | + | Finds the last occurrence of {{c|ch}} (after conversion to {{c|char}}) in the byte string pointed to by {{c|str}}. The terminating null character is considered to be a part of the string and can be found if searching for {{c|'\0'}}. |
===Parameters=== | ===Parameters=== | ||
− | {{ | + | {{par begin}} |
− | {{ | + | {{par|str|pointer to the null-terminated byte string to be analyzed}} |
− | {{ | + | {{par|ch|character to search for}} |
− | {{ | + | {{par end}} |
===Return value=== | ===Return value=== | ||
− | Pointer to the found character in {{ | + | Pointer to the found character in {{c|str}}, or null pointer if no such character is found. |
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | #include <cstring> | |
− | + | #include <iostream> | |
+ | |||
+ | int main() | ||
+ | { | ||
+ | char input[] = "/home/user/hello.c"; | ||
+ | char* output = std::strrchr(input, '/'); | ||
+ | if (output) | ||
+ | std::cout << output + 1 << '\n'; | ||
+ | } | ||
+ | |output= | ||
+ | hello.c | ||
}} | }} | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strchr}} |
− | {{ | + | {{dsc inc|cpp/string/wide/dsc wcsrchr}} |
− | {{ | + | {{dsc inc|cpp/string/basic_string/dsc rfind}} |
− | {{ | + | {{dsc see c|c/string/byte/strrchr}} |
+ | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 14:41, 6 June 2023
Defined in header <cstring>
|
||
const char* strrchr( const char* str, int ch ); |
||
char* strrchr( char* str, int ch ); |
||
Finds the last occurrence of ch (after conversion to char) in the byte string pointed to by str. The terminating null character is considered to be a part of the string and can be found if searching for '\0'.
Contents |
[edit] Parameters
str | - | pointer to the null-terminated byte string to be analyzed |
ch | - | character to search for |
[edit] Return value
Pointer to the found character in str, or null pointer if no such character is found.
[edit] Example
Run this code
#include <cstring> #include <iostream> int main() { char input[] = "/home/user/hello.c"; char* output = std::strrchr(input, '/'); if (output) std::cout << output + 1 << '\n'; }
Output:
hello.c
[edit] See also
finds the first occurrence of a character (function) | |
finds the last occurrence of a wide character in a wide string (function) | |
find the last occurrence of a substring (public member function of std::basic_string<CharT,Traits,Allocator> )
| |
C documentation for strrchr
|