SA-MP Forums Archive
how to - 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: how to (/showthread.php?tid=292448)



how to - sent161 - 23.10.2011

Hello, how you can take string value from the array in which the values ​​are separated by |
For example I have string = "sent | dima | serinc |...";
I need the value of "dima"
Sorry for my english, I'm Russian


Re: how to - =WoR=Varth - 23.10.2011

Use sscanf, check out it's topic to find out how to do that. Tell us if you get any errors.


Re: how to - sent161 - 23.10.2011

I understand you, but I'm not really friends with sscanf. Here is my attempt without him
PHP код:
            case 512:
            {
                if(!
response) return 1;
                new 
bID GetPlayerVirtualWorld(playerid);
                if(
BizInfo[bID][bProdPrice][listitem] > PlayerInfo[playerid][pMoney])
                return 
SendClientMessage(playerid,-1,"Ó âàñ íåäîñòàòî÷íî äåíåã!");
                new 
dByffer[1024],selectedid;
                
dByffer=BizInfo[bID][bItem];
                for(new 
i;i<strlen(BizInfo[bID][bItem]);i++)
                {
                    if(
selectedid == listitem)
                    {
                        for(new 
y;y<strlen(BizInfo[bID][bItem]);y++)
                        {
                            if(
== 0x7c)
                            {
                                
strdel(dByffer,y,strlen(BizInfo[bID][bItem]));
                            }
                        }
                    }
                    if(
== 0x7c)selectedid++;
                    
strdel(dByffer,0,1);
                }
                
format(String,128,"Âû êóïèëè %s çà %d $",dByffer,BizInfo[bID][bProdPrice][listitem]);
                
SendClientMessage(playerid,-1,String);
            } 
Unfortunately this code does not work!


Re: how to - =WoR=Varth - 23.10.2011

pawn Код:
sscanf(stringtoextract,"s[128]'|'s[128]'|'s[128]",string,strings,anotherstring);



Re: how to - sent161 - 23.10.2011

All right. But I need a single value, and the provisions of which are known to me. More precisely, it equals the value of listitem.
So the same amount of value can be changed ..
There may be 3 and 4, 100 ...


Re: how to - =WoR=Varth - 23.10.2011

I don't get what you mean.


Re: how to - sent161 - 23.10.2011

Ok.
I have an empty array. Somehow I fill it ...
Next, I need to read a particular part of it.
This part is marked with two sides by |.
But the location of values ​​in the array depends on the variable ...
string = "| sent | serinc | etc ...|"
If var = 1, then string = "sent". If 2, then string = "serinc"


Re: how to - =WoR=Varth - 23.10.2011

pawn Код:
format(string,sizeof(string),"s[128]");
for(new i=1;i<var;i++)
{
    strins(string,"{s[128]}",0);
}
sscanf(stringtoextract,string,ouputhere);
Untested.


Re: how to - sent161 - 23.10.2011

I do not understand ... This code should append the value of the array "string"


Re: how to - =WoR=Varth - 23.10.2011

pawn Код:
format(string,sizeof(string),"s[128]");//Creating standard sscanf parameter
for(new i=1;i<var;i++)
{
    strins(string,"{s[128]}'|'",0);//Each count on var, it will insert "quiet" parameter that will not be stored but used to separate string (Missed '|')
}
sscanf(stringtoextract,string,ouputhere);//Extracted here