SA-MP Forums Archive
How to concatenate strings - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: How to concatenate strings (/showthread.php?tid=650257)



How to concatenate strings - ForestCZE - 24.02.2018

Hello everyone

I've got following code:

PHP Code:
new radiolist[500]; //I've got about 16 radios, but it's not necessary to show all lines of my code
strcat(radiolist"Stanice\tPosluchačů\n");
strcat(radiolist"Vypnout rбdio\n");
strcat(radiolist"Evropa 2\t%i\n"listeners[0]);
strcat(radiolist"Rбdio Express\t%i\n"listeners[1]);
strcat(radiolist"Dance Rбdio\t%i"listeners[2]);
ShowPlayerDialogEx(playeridD_RADIODIALOG_STYLE_TABLIST_HEADERS"Rбdio"radiolist"Zvolit""Zavřнt"); 
The question is - How correctly use format and strcat because of "listeners" variable, please? Thanks in advance for a help


Re: How to concatenate strings - iKarim - 24.02.2018

That's usually how it's done:

PHP Code:
new message[24], value 5;
strcat(string"hello");
format(stringsizeof string"%s world! %i"stringvalue); 
You pass the actual string to the format function and add whatever you need.


Re: How to concatenate strings - RogueDrifter - 24.02.2018

It's usually better to use strcat in case if you don't need to pass variables into the final dialog/message but if you do then you can reformat the string like what iKarim said.


Re: How to concatenate strings - ForestCZE - 24.02.2018

Quote:
Originally Posted by iKarim
View Post
That's usually how it's done:

PHP Code:
new message[124], value 5;
strcat(string"hello");
format(stringsizeof string"%s world! %i"stringvalue); 
You pass the actual string to the format function and add whatever you need.
I'm sorry, but I probably didn't understand you. This code:

PHP Code:
new radiolist[500];
strcat(radiolist"Stanice\tPosluchačů\n");
strcat(radiolist"Vypnout rбdio\n");
format(radiolistsizeof(radiolist), "Evropa 2\t%i\n"listeners[0]); 
does not work.


Re: How to concatenate strings - iKarim - 24.02.2018

Quote:
Originally Posted by ForestCZE
View Post
I'm sorry, but I probably didn't understand you. This code:

PHP Code:
new radiolist[500];
strcat(radiolist"Stanice\tPosluchačů\n");
strcat(radiolist"Vypnout rбdio\n");
format(radiolistsizeof(radiolist), "Evropa 2\t%i\n"listeners[0]); 
does not work.
You need to pass the radiolist variable as a param in the format too, also notice the %s place.


PHP Code:
new radiolist[500];
strcat(radiolist"Stanice\tPosluchačů\n");
strcat(radiolist"Vypnout rбdio\n");
format(radiolistsizeof(radiolist), "%sEvropa 2\t%i\n"radiolistlisteners[0]); 



Re: How to concatenate strings - ForestCZE - 24.02.2018

Quote:
Originally Posted by iKarim
View Post
You need to pass the radiolist variable as a param in the format too, also notice the %s place.


PHP Code:
new radiolist[500];
strcat(radiolist"Stanice\tPosluchačů\n");
strcat(radiolist"Vypnout rбdio\n");
format(radiolistsizeof(radiolist), "%sEvropa 2\t%i\n"radiolistlisteners[0]); 
Yes, I already realized that and you were faster than my edit. Thank you so much


Re: How to concatenate strings - DTV - 26.02.2018

You could use sprintf from here so that you can format strings within strcat.