Something bad with this function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Something bad with this function (
/showthread.php?tid=411218)
Something bad with this function -
JavoDiaz - 28.01.2013
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!
Re: Something bad with this function -
JaKe Elite - 28.01.2013
What if, the string contains a word { and }. It will remove the word. Even it's not the color.
Re: Something bad with this function -
JavoDiaz - 28.01.2013
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.
Re: Something bad with this function -
JavoDiaz - 28.01.2013
uppie
Re: Something bad with this function -
LarzI - 28.01.2013
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;
}
Re: Something bad with this function -
JavoDiaz - 28.01.2013
I'll try Southclaw's function, thanks.