strdel?
#1

In a script, there is a string that holds ids. For example, it may look like this: |4|32|64|35|

If a player's database id is located in that string, they will have access to a certain feature. But what I can't quite think of, is what to do if I want to remove, say id 32 from that string. I couldn't use strdel, because there is no way (That I know of) to see where |32| starts and ends in the string. What i'm looking for, is something like strfind, to delete what it finds.
Reply
#2

Here's one way:
pawn Код:
new start, bool:foundstart = false, end;
for(new i = 0; i < strlen(string); i ++)
{
    if(foundstart == false)
    {
        if(string[i] == '3')
        {
            start = i;
            foundstart = true;
        }
    }
    else
    {
        if(string[i] == '2')
        {
            end = i;
            break;
        }
    }
}

strdel(string, start, end);
You get the start character and end character, and then you just replace it for the 3 and the 2.
Reply
#3

You can use strfind to get the position, then delete the part of the string with strdel.
Reply
#4

But strfind doesn't return the end position.
Reply
#5

Alright, true. A work around would be to get the amount of numbers the id has and then add it to the start position to obtain the end position.
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
So? "|32|" is 4 characters, so the end is "start + 4". A better question would be why are IDs being stored in a string in the first place? There are VASTLY more efficient ways to do that.
What would be a better way to store multiple ids in one variable? It saves in the database as one thing.

I didn't know that strfind returns the starting postion, I guess that will give me everything that I need
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)