how to
#1

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

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

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!
Reply
#4

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

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

I don't get what you mean.
Reply
#7

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"
Reply
#8

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)