remove minus (-)
#1

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<<
Reply
#2

pawn Код:
printf("result: %s, NoMinus("some-string-with-minus"));
This wouldn't compile.
Reply
#3

Don't you mean
pawn Код:
printf("result: %s", NoMinus("some-string-with-minus"));
Reply
#4

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
Reply
#5

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;
}
Reply
#6

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;
}
Reply
#7

thanks wups!
but do i need so big string?
Reply
#8

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.
Reply
#9

Next Time, Mr. Fox
Reply
#10

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);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)