AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   What operator i have to use to join few strings? (https://forums.alliedmods.net/showthread.php?t=27968)

orglee 05-03-2006 22:20

What operator i have to use to join few strings?
 
What operator i have to use to join 3 string?
Example:
Code:

client_print(id,print_chat,hostname)
I want this code to display =
* [hostname] Some msg.
Ive tried to join them like this:
Code:

client_print(id,print_chat,"["+hostname+"]")
Please tell me how i can join strings.
Best Regards

SweatyBanana 05-03-2006 22:34

Did u want it to actually display your hostname?




Code:
new HName[32] get_cvar_string("hostname",HName,31) client_print(id,print_chat,"%s",HName)

Smokey485 05-03-2006 22:38

Code:
new hostname = get_cvar_string("hostname") client_print(id,print_chat,"Welcome to %s!", hostname)
Would display the server name where %s is.[/small]

SweatyBanana 05-03-2006 22:39

Im sorry...I wrote the wrong thing..

I just edited it lol..

Thanks for the post after mine :)

Smokey485 05-03-2006 23:11

Quote:

Originally Posted by SweatyBanana
Im sorry...I wrote the wrong thing..

I just edited it lol..

Thanks for the post after mine :)

Im good.

Xanimos 05-03-2006 23:40

Quote:

Originally Posted by Smokey485
Quote:

Originally Posted by SweatyBanana
Im sorry...I wrote the wrong thing..

I just edited it lol..

Thanks for the post after mine :)

Then give me karma, its the only correct way to thank me!

Don't be cocky/silly.

FatalisDK 05-04-2006 00:35

@ Original question:

If your function doesn't have formatting built into it(as seen in client_print), you can use format.

Here's an example.

Code:
new szName[32], szHostname[32], szOutput[64]     get_user_name(id, szName, 31) get_cvar_string("hostname", szHostname, 31)     format(szOutput, 63, "Hello %s, Welcome to %s. You are player #%i.", szName, szHostname, get_user_userid(id))

teame06 05-04-2006 01:22

Quote:

Originally Posted by Smokey485
Code:
new hostname = get_cvar_string("hostname") client_print(id,print_chat,"Welcome to %s!", hostname)
Would display the server name where %s is.[/small]

This is a bad way to do this. You didn't even set the array size. Probably get a out of bound error to.

Xanimos 05-04-2006 02:23

it just wouldn't even compile. get_cvar_string() requires more fields than given here.

orglee 05-04-2006 06:58

I thought there is some operator like in PHP where i can join two string with
dot like this
Code:

PHP CODE:
<?php
$someVar = "some text".$someOtherVar."Some text";
?>

I just dont understand what means thous:
%s
#%i
I coldnt find it in help.
Can you tell me where is explanation to thous ...
hmm i dont know even what they are.


All times are GMT -4. The time now is 05:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.