strdel? - 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: strdel? (
/showthread.php?tid=568984)
strdel? -
TakeiT - 27.03.2015
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.
Re: strdel? -
SickAttack - 27.03.2015
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.
Re: strdel? -
Abagail - 27.03.2015
You can use strfind to get the position, then delete the part of the string with strdel.
Re: strdel? -
SickAttack - 27.03.2015
But strfind doesn't return the end position.
Re: strdel? -
SickAttack - 27.03.2015
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.
Re: strdel? -
TakeiT - 27.03.2015
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