split string by sscanf ? -
3417512908 - 28.10.2018
Код:
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
Re: split string by sscanf ? -
3417512908 - 28.10.2018
bump to first
Re: split string by sscanf ? -
Calisthenics - 28.10.2018
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.
Re: split string by sscanf ? -
3417512908 - 28.10.2018
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.
Re: split string by sscanf ? -
Calisthenics - 28.10.2018
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
Re: split string by sscanf ? -
3417512908 - 28.10.2018
Quote:
Originally Posted by Calisthenics
|
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.