I'm trying to figure out a decent way to replace spaces (\x20) that occur next to each other with &nbps;'s.
string SPACE = "\x20";
string str = "<span style=\"color:#f00;\""> Three Spaces</span>";
size_t pos = str.find(SPACE, 0);
size_t prev = 0;
size_t start = 0;
size_t length = 0;
while (pos != string::npos)
{
prev = pos;
if (prev == (start + 1))
{
// this is where i start to get lost...
}
else
{
start = pos;
}
pos = str.find(SPACE, pos + 1);
}
So my end result of the str would be
<span style="color:#f00;"> Three Spaces</span>
Notice that the space within the span is kept the same.
I'm having a rough time thinking of the logic to keep track of how many spaces are next to each other. I was going to find the start position, store a "length" of how many spaces it finds, then do a substr() with the pos and length.