remove minus (-) - 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: remove minus (-) (
/showthread.php?tid=286937)
remove minus (-) - Unknown123 - 01.10.2011
pawn Код:
main()
{
printf("result: %s", NoMinus("some-string-with-minus"));
}
stock NoMinus(string[])
{
for(new i; i < strlen(string); i++)
{
if(string[i] == '-')
{
strdel(string, i, i+1);
}
}
return string;
}
this return >>Script[gamemodes/gamemode.amx]: Run time error 5: "Invalid memory access"<<
but it should return >>result: somestringwithminus<<
Re: remove minus (-) -
wups - 01.10.2011
pawn Код:
printf("result: %s, NoMinus("some-string-with-minus"));
This wouldn't compile.
Re: remove minus (-) -
FireCat - 01.10.2011
Don't you mean
pawn Код:
printf("result: %s", NoMinus("some-string-with-minus"));
Re: remove minus (-) - Unknown123 - 01.10.2011
Quote:
Originally Posted by wups
pawn Код:
printf("result: %s, NoMinus("some-string-with-minus"));
This wouldn't compile.
|
i accidently removed a " when i posted this, so? any help i can get?
post edited
Re: remove minus (-) -
FireCat - 01.10.2011
pawn Код:
main()
{
printf("result: %s", NoMinus("some-string-with-minus"));
}
stock NoMinus(string[])
{
for(new i; i < strlen(string); i++)
{
if(strcmp(string[i],"-") == 0)
{
strdel(string, i, i+1);
}
}
return string;
}
Re: remove minus (-) -
wups - 01.10.2011
Quote:
Originally Posted by Unknown123
i accidently removed a " when i posted this, so? any help i can get?
post edited
|
pawn Код:
stock NoMinus(string[])
{
new string2[1024],
var;
for(new i,j = strlen(string); i < j; i++)
{
if(string[i] != '-')
{
string2[var]=string[i];
var++;
}
}
return string2;
}
Re: remove minus (-) - Unknown123 - 01.10.2011
thanks wups!
but do i need so big string?
Re: remove minus (-) -
wups - 01.10.2011
Quote:
Originally Posted by Unknown123
thanks wups!
but do i need so big string?
|
Set it to the length of the max length of used strings.
for example, if you're using it only for "some-string-with-minus", you can set 1024 to 22. I set it to 1024, to avoid problems. If your strings will exceed 1024 characters change it to more.
Re: remove minus (-) -
KoczkaHUN - 03.10.2011
Next Time, Mr. Fox
Re: remove minus (-) -
AndreT - 03.10.2011
There's no need for such a big function. I think you could try something like this:
pawn Код:
while((i = strfind(string, "-", false)) != -1) strdel(string, i, i+1);