Raised This Month: $51 Target: $400
 12% 

Joining 2 Strings together


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Acid07
Member
Join Date: May 2009
Old 10-09-2010 , 17:55   Joining 2 Strings together
Reply With Quote #1

Hey. I'm currently writing a plug-in I would like to release... BUT I've hit a wall. I need to join 2 strings together e.g. "Hello" and "World" would become "Hello World"

I need it as simple as possible and I've Looked all everywhere on how to do so.

If anyone would kindly give me the code or just point me in the correct direction it would be a big help. I will give credit for the specific code if you do give me it!

Thanks for the help guys =)
Acid07 is offline
DieTeetasse
Senior Member
Join Date: Jul 2009
Old 10-09-2010 , 18:12   Re: Joining 2 Strings together
Reply With Quote #2

StrCat

Syntax:
stock StrCat(String:buffer[], maxlength, const String:source[])


Usage:
buffer String to append to.
maxlength Maximum length of entire buffer.
source Source string to concatenate.

Notes:
Concatenates one string onto another.

Return:
Number of bytes written.

Source:
http://docs.sourcemod.net/api/index....d=show&id=643&
__________________
DieTeetasse is offline
Acid07
Member
Join Date: May 2009
Old 10-09-2010 , 18:50   Re: Joining 2 Strings together
Reply With Quote #3

I don't suppose you would mind helping me understand how to implement this?

I've got 2 convars (that are both strings) and I would like to get a single string from both of them that I can print to chat.

I'm sorry for pestering but I've never produced a plug-in worthy of anything.
Acid07 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 10-09-2010 , 19:21   Re: Joining 2 Strings together
Reply With Quote #4

stock StrCat(String:buffer[], maxlength, const String:source[])

basically in code:
PHP Code:
decl String:s_Buffer[32];
decl String:s_Source[32];
Format(s_Buffer32"SomeString");
Format(s_Source32"AnotherString");

// This is the line you're interested in, the rest is to demonstate
StrCat(s_Buffer32s_Source);

PrintToChatAll("%s"s_Buffer); 
Displays "SomeStringAnotherString"
__________________
Silvers is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 10-09-2010 , 20:09   Re: Joining 2 Strings together
Reply With Quote #5

This will work with the 2 convars you're going to use
PHP Code:
decl String:s_Buffer[32];
decl String:s_Source[32];
GetConVarString(HANDLEtoCVARs_Buffer32);
GetConVarString(HANDLEtoCVARs_Source32);
StrCat(s_Buffer32s_Source); // This is the line you're interested in, the rest is to demonstate
PrintToChatAll("%s"s_Buffer); 
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 10-09-2010 , 20:14   Re: Joining 2 Strings together
Reply With Quote #6

Even better
__________________
Silvers is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 10-09-2010 , 22:05   Re: Joining 2 Strings together
Reply With Quote #7

If you need to do any formatting to them (like adding a space between them), it's often better to just use Format.


PHP Code:
decl String:DestinationString[128];
Format(DestinationStringsizeof(DestinationString), "%s %s"String1String2); 
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Acid07
Member
Join Date: May 2009
Old 10-10-2010 , 05:15   Re: Joining 2 Strings together
Reply With Quote #8

Thanks all! I will list everyone above for helping in the credits =).
Acid07 is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 18:27.


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