Should i use "format" for this?? -
iggy1 - 12.01.2011
Hello i was wondering if anyone would know a better (more efficient) way of adding text to a string than format? I know about "strins" but i can't specify which posistion to insert the text. I've never needed to do this up untill now so i'm a bit stumped. Here is the code to give you an idea of what i mean, incase you didn't get it.
Its using y_groups/y_commands so keep in mind this function "Command_GetNext(i, playerid)" just returns a command name.
pawn Код:
new
cmdlist[264],
cmdcount = Command_GetPlayerCommandCount(playerid);
for(new i; i < cmdcount; i++)
{
format(cmdlist, sizeof(cmdlist), "%s/%s\n", cmdlist, Command_GetNext(i, playerid));//i wont know where to insert the new command with strins
}
ShowPlayerDialog(playerid, COMMAND_DIALOG, DIALOG_STYLE_LIST, "{00ff01}Here is a list of all commands available to you", cmdlist, "Ok","Back");
Thanks in advance. Forgive the indentation i copy pasted it from a nested block of code.
Re: Should i use "format" for this?? -
Jeffry - 12.01.2011
Maybe:
pawn Код:
strins(cmdlist, Command_GetNext(i, playerid), strlen(cmdlist)-1);
This will insert it at the last pos. Hopefully ^^
Re: Should i use "format" for this?? -
iggy1 - 12.01.2011
Ah that probably would work actually. Just realised i will probably have to stick to "format" for the newline char
any ideas on a way around that?
Thanks for the quick response.
EDIT: Just realised i can use strins for newline too dur..
Re: Should i use "format" for this?? -
Jeffry - 12.01.2011
Use it twice:
pawn Код:
strins(cmdlist, Command_GetNext(i, playerid), strlen(cmdlist)-1);
strins(cmdlist, "\n", strlen(cmdlist)-1); //oh, and if the Command_GetNext does not return a '/' then add the / after the n
But might be slower then, dunno.
Re: Should i use "format" for this?? -
RyDeR` - 12.01.2011
Just use the format. What's wrong with it?
Re: Should i use "format" for this?? -
iggy1 - 12.01.2011
I guess it would still be faster if the string is larger dunno. I'll stick to strins.
Thanks.
EDIT:
Quote:
Originally Posted by RyDeR`
Just use the format. What's wrong with it?
|
Nothing is wrong with it, i just read somewhere that formating a string isn't the best way to append new text to it. Say if i had 500 commands it might be better using strins or it wont make any difference? IDK
Re: Should i use "format" for this?? -
Finn - 12.01.2011
strcat
Re: Should i use "format" for this?? -
iggy1 - 12.01.2011
Spoiled for choice now
Might have to to a little testing and pick one.
Thanks all.