SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 24/02/2018, 10:25 AM   #1
ForestCZE
Little Clucker
 
Join Date: Feb 2018
Posts: 8
Reputation: 0
Default How to concatenate strings

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
ForestCZE is offline   Reply With Quote
Old 24/02/2018, 10:33 AM   #2
iKarim
Gangsta
 
iKarim's Avatar
 
Join Date: Oct 2015
Posts: 587
Reputation: 133
Default Re: How to concatenate strings

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.
iKarim is offline   Reply With Quote
Old 24/02/2018, 10:44 AM   #3
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,565
Reputation: 338
Default Re: How to concatenate strings

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.
__________________
Code:
I'm available to script stuff for cash PM me here or on discord @ Andy[RDZ]#0040
[Tutorial]:Anti-cheat guide ||Mini-game 101||VC/LC maps install||
Array index out of bounds


[Github]:Link [Pastebin]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 24/02/2018, 10:51 AM   #4
ForestCZE
Little Clucker
 
Join Date: Feb 2018
Posts: 8
Reputation: 0
Default Re: How to concatenate strings

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.
ForestCZE is offline   Reply With Quote
Old 24/02/2018, 10:53 AM   #5
iKarim
Gangsta
 
iKarim's Avatar
 
Join Date: Oct 2015
Posts: 587
Reputation: 133
Default Re: How to concatenate strings

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]); 
iKarim is offline   Reply With Quote
Old 24/02/2018, 11:00 AM   #6
ForestCZE
Little Clucker
 
Join Date: Feb 2018
Posts: 8
Reputation: 0
Default Re: How to concatenate strings

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
ForestCZE is offline   Reply With Quote
Old 26/02/2018, 11:49 PM   #7
DTV
Gangsta
 
DTV's Avatar
 
Join Date: Dec 2010
Posts: 507
Reputation: 95
Default Re: How to concatenate strings

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




Bringing the nuclear post apocalyptic setting to SA-MP, click the banners to view the forum or Discord server.
DTV is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings SumX Scripting Help 3 08/08/2015 12:31 PM
Strings Ryan McDuff Scripting Help 2 01/02/2014 06:08 AM
Need help with strings. xOFxK1LLER Scripting Help 2 30/04/2012 02:11 PM
Help me please, this strings... DatNewbie Scripting Help 7 20/03/2012 04:39 AM
[Tutorial] Strings: How to... RebeloX Lançamentos/Releases 14 14/11/2011 11:16 PM


All times are GMT. The time now is 01:38 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.