Something bad with this function
#1

Hi, I am doing a function to delete the colors like {FFFFFF} from a string, but I can't do that, when I test it in a console, the console do a beep instead of show the result, I will appreciate help.


Function:

pawn Код:
RemoveColorsFromString(rString[])
{
    new firstPos = strfind(rString, "{", false);
    new secondPos = strfind(rString, "}", false);
    if(firstPos > 0 && secondPos > firstPos)
    {
        while(firstPos != -1)
        {
            firstPos = strfind(rString, "{", false);
            secondPos = strfind(rString, "}", false);
            strdel(rString, firstPos, secondPos);
        }
        return rString;
    }
    else return rString;
}

Thanks!
Reply
#2

What if, the string contains a word { and }. It will remove the word. Even it's not the color.
Reply
#3

I know, but I need this function and in my case nobody will put {word} so if someone can help me I'll be very grateful. Thanks.
Reply
#4

uppie
Reply
#5

Southclaw did this in the Useful Functions thread: http://forum.sa-mp.com/showpost.php?...postcount=2933

You may also add a ishex check with ******' function from YSI
pawn Код:
stock ishex(str[])
{
    //P:3("ishex called: \"%s\"", str);
    new
        i,
        cur;
    if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) i = 2;
    while (str[i])
    {
        cur = str[i++];
        if (!(('0' <= cur <= '9') || ('A' <= cur <= 'F') || ('a' <= cur <= 'f'))) return 0;
    }
    return 1;
}
Reply
#6

I'll try Southclaw's function, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)