How to cut a piece of text?
#1

How to cut the first 8 characters?
Код HTML:
{00FF00}text
Reply
#2

What do you mean ? You want to delete "{00ff00}" ?
Can you explain more ?
Reply
#3

Use strmid.

https://sampwiki.blast.hk/wiki/Strmid


strmid(string, "ItWillCopeThis notthis", 1, 14); //string contains "ItWillCopeThis"

1 stands for the first character and 14 for the last.
Reply
#4

Quote:
Originally Posted by ikbenremco
Посмотреть сообщение
Use strmid.

https://sampwiki.blast.hk/wiki/Strmid


strmid(string, "ItWillCopeThis notthis", 1, 14); //string contains "ItWillCopeThis"

1 stands for the first character and 14 for the last.
In that case Strdel will be better
pawn Код:
new string[42] = "We will delete everything apart from this";
strdel(string, 0, 37); // string is now "this"
Reply
#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
#6

Big thanks guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)