Should i use "format" for this??
#1

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

Maybe:

pawn Код:
strins(cmdlist, Command_GetNext(i, playerid), strlen(cmdlist)-1);
This will insert it at the last pos. Hopefully ^^
Reply
#3

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

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

Just use the format. What's wrong with it?
Reply
#6

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

strcat
Reply
#8

Spoiled for choice now Might have to to a little testing and pick one.

Thanks all.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)