How to cut a piece of text?
#5

If you don't know the position of that piece of text and you want to remove the first hex color {RRGGBB}:
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;
}
I know it can be written in a better way.

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 );
RemoveHexColors will be called as many as hex color exists + 1.
Reply


Messages In This Thread
How to cut a piece of text? - by LastChaos - 29.11.2013, 13:40
Re: How to cut a piece of text? - by xVIP3Rx - 29.11.2013, 13:41
Re: How to cut a piece of text? - by ikbenremco - 29.11.2013, 13:44
Re: How to cut a piece of text? - by xVIP3Rx - 29.11.2013, 13:47
Re: How to cut a piece of text? - by Konstantinos - 29.11.2013, 14:11
Re: How to cut a piece of text? - by LastChaos - 29.11.2013, 14:27

Forum Jump:


Users browsing this thread: 1 Guest(s)