string formating question
#1

format(aim, sizeof(aim), "%s[R%s] [%s/3 warns] %s\n", aim, test, warns, query);

i've seen people formating a string like this and i don't understand what's the point,i mean why do they include the string itself while formating the string, the first placeholder "%s" represents "aim",wich is the string that its formated

format(aim, sizeof(aim), "%S [R%s] [%s/3 warns] %s\n", AIM, test, warns, query);

i wrote the placeholder with caps and what it represents,the AIM witch is the string itself,i don't understand
Reply
#2

It's used to attach something to a string while also using other specifiers.

For example, if you have a list you want to show in a dialog and you want to format each line with values/text from an array or so, you can use this to repeatedly attach the new line to the string without using a temporary array/string.

Code:
new some_models[] = {13592, 1225, 2323};

new string[100];

for(new i = 0; i < sizeof(some_models); i ++)
{
format(string, sizeof(string), "%s%d\n", string, some_models[i]);
}
And the result will be

"13592\n1225\n2323\n"

It basically is just used as strcat with format specifiers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)