For example, if I have
string x = "dog:cat";
and I want to extract everything after the ":", and return cat. What would be the way to go about doing this?
In C, the strtok() function is used to split a string into a series of tokens based on a particular delimiter. A token is a substring extracted from the original string.
Search for a character in a string - strchr & strrchr The strchr function returns the first occurrence of a character within a string. The strrchr returns the last occurrence of a character within a string. They return a character pointer to the character found, or NULL pointer if the character is not found.
C program to fetch substring of a string using strncpy function. char *strncpy (char *destination, const char *source, size_t num); In this program we are using an extra subString character array to store sub-string form input array. We initialize it with null character using memset function.
strtok remembers the last string it worked with and where it ended. To get the next string, call it again with NULL as first argument.
Try this:
x.substr(x.find(":") + 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With