この種の文字列形式があるとします。
"<RGB:255,0,0>this text is colored RED.<RGB:0,255,0> While this text is colored GREEN";
ie 255,0,0内の値を抽出し、<RGB>
それを他の変数に入れ、char
s from '<'
to を削除し'>'
ます。
これまでの私のコード:
//this function is called after the loop that checks for the existence of '<'
void RGB_ExtractAndDelete(std::string& RGBformat, int index, RGB& rgb)
{
int i = index + 5; //we are now next to character ':'
std::string value;
int toNumber;
while (RGBformat[i] != ',')
{
value += RGBformat[i++];
}
++i;
std::stringstream(value) >> toNumber;
rgb.R = toNumber;
value = "";
while (RGBformat[i] != ',')
{
value += RGBformat[i++];
}
++i;
std::stringstream(value) >> toNumber;
value = "";
rgb.G = toNumber;
while (RGBformat[i] != '>')
{
value += RGBformat[i++];
}
++i;
std::stringstream(value) >> toNumber;
value = "";
rgb.B = toNumber;
//I got the right result here which is
//start: <, end: >
printf("start: %c, end: %c\n", RGBformat[index], RGBformat[i]);
//but fail in this one
//this one should erase from '<' until it finds '>'
RGBformat.erase(index, i);
}
文字列の先頭に を配置する<RGB:?,?,?>
と機能しますが、「<」以外の文字の横にあると失敗します。または、これを行うためのより良いアプローチを提案できますか?