我有以下格式的字符串:
str1 = "a, b, c, d, e";
str2 = "aa, ba, ca, da, essd";
str2 = "aass, bsda, cads, dsda, esssdsd";
我想在拆分后提取字符串的结尾 --> e
, essd
, esssdsd
。
答案 0 :(得分:1)
假设这些是 std::string
,我会使用 rfind
找到最后一次出现的分隔符,然后从那里取出一个子字符串。例如:
size_t index = str.rfind(", ");
string last_element = str.substr(index + 2); // 2 is the size of the delimiter