Transfering strings -
MP2 - 17.07.2011
How do you transfer a string from one array to another?
For example if I have
new string1[8] = "Hello";
and
new string2[8] = "Goodbye";
How do I set string1 to what is in string2?
Re: Transfering strings -
=WoR=Varth - 17.07.2011
pawn Код:
format(string1,sizeof(string1),"%s",string2);
Re: Transfering strings -
Lorenc_ - 17.07.2011
pawn Код:
format(string1, sizeof(string1), "%s", string2);
EDIT: was abit too late, had this page tabbed sorry.
Re: Transfering strings -
Donya - 17.07.2011
pawn Код:
strmid(string2, string1, false, strlen(string1), sizeof(string2));
pawn Код:
strmid(string2, string1, false, strlen(string1), 128);
Re: Transfering strings -
SchurmanCQC - 17.07.2011
IF you wanted a 'hello goodbye' string, you could do this:
pawn Код:
format(string1, sizeof(string1), "%s %s",string1, string2);
Yes, you can insert a string into itself.
Re: Transfering strings -
Donya - 17.07.2011
Quote:
Originally Posted by Schurman
IF you wanted a 'hello goodbye' string, you could do this:
pawn Код:
format(string1, sizeof(string1), "%s %s",string1, string2);
Yes, you can insert a string into itself.
|
strcat (appends)
strins (recreates it)
Re: Transfering strings -
=WoR=Varth - 17.07.2011
http://forum.sa-mp.com/showpost.php?...1&postcount=19
Re: Transfering strings -
MP2 - 17.07.2011
I think strmid would be easiest, but is it the best? Thanks for the replies guys.
Re: Transfering strings -
Donya - 17.07.2011
Its' the fastest, besides strcpy that uses strcat I believe.
Re: Transfering strings -
leong124 - 17.07.2011
If the two arrays/strings has the same size, using
pawn Код:
new string1[8] = "Hello",string2[8] = "world!";
string1 = string2;
will be the fastest (and easy to use).
If you want to add some more strings behind a string you can use strcat/strcpy.
However, if more than 4-5 strcat is required to make a string, or there's non-string values to be added into the string, format will be faster.
pawn Код:
new string[128] = "Hello,",playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
strcat(string,playername);
strcat(string,"! Welcome to ");
strcat(string,servername);
strcat(string,"!");
has the similar efficiency as:
pawn Код:
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),"Hello,%s! Welcome to %s!",playername,servername);