split string by sscanf ?
#1

Код:
format(string,sizeof string,"{ffffff}[ID%d] "MYCARY"%s\n",MyVeh[i][VID],VehicleNames[GetVehicleModel(MyVeh[i][Veh])-400]);
here's a string,and i want to get "[ID%d]",that number(%d) maybe is 1,10,100,1000...or more.
notice:that string is using in dialog inputtext,so hex color can ignore.
sscanf can split,but i dont know how to do it
Reply
#2

bump to first
Reply
#3

pawn Код:
new id;
sscanf(inputtext[3], "p<]>d{s[50]}", id);
inputtext will be "[ID842] Infernus"
inputtext[3] will skip the first 3 characters and be "842] Infernus"
the trick is to split using ] delimiter "p<]>" instead of space, so it separates into two parts "842" and "Infernus"
"d" specifier will be for the first part and will be stored in `id` variable.
"{s[50]}" is called quiet string and will be ignored. Anything inside { } are not stored in variables.
Reply
#4

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
pawn Код:
new id;
sscanf(inputtext[3], "p<]>d{s[50]}", id);
inputtext will be "[ID842] Infernus"
inputtext[3] will skip the first 3 characters and be "842] Infernus"
the trick is to split using ] delimiter "p<]>" instead of space, so it separates into two parts "842" and "Infernus"
"d" specifier will be for the first part and will be stored in `id` variable.
"{s[50]}" is called quiet string and will be ignored. Anything inside { } are not stored in variables.
it work,but here is still a problem:
Код:
sscanf warning: Format specifier does not match parameter count.
Reply
#5

Are you certain this warning is given from this line? An older version of sscanf that does not support quiet specifiers might give the same warning.

Update to latest version: https://github.com/maddinat0r/sscanf/releases
Reply
#6

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
Are you certain this warning is given from this line? An older version of sscanf that does not support quiet specifiers might give the same warning.

Update to latest version: https://github.com/maddinat0r/sscanf/releases
by checked, i've been long time for not update sscanf, now i updated and fixed it , and that function is work awesome,thank a lot bro.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)