How to concatenate strings
#1

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

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

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

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

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]); 
Reply
#6

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)