Hi I am hitting std::out_of_range: basic_string::substr
in the following code. Have been trying hard to fix it but cant get it done.
std::string orig_str = "1-1,2-3,4-4,56-75,77-77";
size_t number_digits;
for (size_t i = 0; i < orig_str.size(); ++i)
{
number_digits = orig_str.find_first_of(",", i) - i - 1;
if(orig_str.find("-", i) != std::string::npos)
if (orig_str.substr(i - number_digits, i - 1) == orig_str.substr(i + 1, i + number_digits))
orig_str.erase(i-number_digits, number_digits + 1);
}
Basically this code is manipulating string to remove some ranges
Expected behavior is:
Input String: “0-0,2-7,88-88” Output String: “0,2-7,88”
AJ, this is the pseudo code we discussed in our chat: