All pastes #993514 Raw Edit

Unnamed

public text v1 · immutable
#993514 ·published 2008-04-22 18:03 UTC
rendered paste body
#include <string>

string str = "a  bc   def";
string new_str = "";

int main()
{
    for (int i = 0; i < length; i++)
    {
        if (str[i] == " ")
            i += get_spaces_num(str, i) - 1;
        new_str += str[i];
    }

    return 0;
}

int get_spaces_num(string str, int index)
{
    int spaces_num = 0;

    while (str[index++] == " ")
        spaces_num++;

    return spaces_num;
}