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?
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?
something like this:
Try this:
Try this one..
What you can do is get the position of ':' from your string, then retrieve everything after that position using substring.
size_t pos = x.find(":"); // position of ":" in str
string str3 = str.substr (pos);
Here is an implementation wrapped in a function that will work on a delimiter of any length:
I know it will be super late but I am not able to comment accepted answer. If you are using only a single character in
find
function use''
instead of""
. As Clang-Tidy saysThe character literal overload is more efficient.
So
x.substr(x.find(':') + 1)