[Solved] Extract int value and string from string [closed]


Assume the string follows the format <int,string>,.... Please find the pseudo-code below:

Loop through the string `str` and
{
    smaller_sign_pos = str.find('<', prev_pos)
    entry_comma_pos = str.find(',', smaller_sign_pos+1)
    greater_sign_pos = str.find('>', entry_comma_pos+1)

    if (all pos values are not `npos`)
    {
        int_value = atoi(str.substr(smaller_sign_pos+1, entry_comma_pos-smaller_sign_pos-1))
        str_value = str.substr(entry_comma_pos+1, greater_sign_pos-entry_comma_pos-1)
        prev_pos = greater_sign_pos+1
        append int_value to int array
        append str_value to string array
        optional: you can check if the comma after '>' exists
    }
    else
    {
        break or set the end of loop flag
    }
}

solved Extract int value and string from string [closed]