29.11.2013, 14:11
If you don't know the position of that piece of text and you want to remove the first hex color {RRGGBB}:
I know it can be written in a better way.
And if you want to remove all the hex colors:
RemoveHexColors will be called as many as hex color exists + 1.
pawn Код:
stock RemoveHexColors( sz_Text[ ] )
{
new
iStart = strfind( sz_Text, "{" ),
iEnd = strfind( sz_Text, "}" ),
bool: using_color = true
;
if( iStart != -1 && iEnd != -1 && iEnd - iStart == 7 )
{
for( new i = iStart + 1; i != iEnd; i++ )
{
if( ( sz_Text[ i ] < 'A' || sz_Text[ i ] > 'Z' ) && ( sz_Text[ i ] < 'a' || sz_Text[ i ] > 'z' ) && ( sz_Text[ i ] < '0' || sz_Text[ i ] > '9' ) )
{
using_color = false;
break;
}
}
if( using_color )
{
strdel( sz_Text, iStart, iEnd + 1 );
return 1;
}
}
return 0;
}
And if you want to remove all the hex colors:
pawn Код:
new
string[ 64 ] = "Some test with colors {00FF00}and {FFFFFF}another color!"
;
while( RemoveHexColors( string ) ) RemoveHexColors( string );