I have a string like this:
std::string string1 = "xjdfhfakdjs%54k34k.-jk34";
I need to get only ""xjdfhfakdjs", but the string is dynamic, not hardcoded so I don't know what is it, the length etc. so I wanted to remove everything after %, and also the % char.
How could I do this?
I believe that will work.
std::string mystr = string1.substr(0, string1.find("%", 0));
std::string the_prefix_you_want = string1.substr(0, string1.find("%"));
See: http://www.cplusplus.com/reference/string/string/find/ and http://www.cplusplus.com/reference/string/string/substr/ for more details
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