Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: DeeKay on Sun 25/02/2024 13:50:53

Title: Concatenating string variable
Post by: DeeKay on Sun 25/02/2024 13:50:53
I am trying to get a GUI label (L1) to show multiple string variables (V1,V2...). I can get it show any one of these using

L1.Text=V1; or L1.Text=V2; etc

What I want, tho, is to show multiple variables together. Eg, something like

L1.Text=V1+V2+V3;

But it doesn't like the + (or the &) operator. Is there an operator for simple concatenation like this?


UPDATE
I managed to get it using string.format as follows:

L1.Text=String.Format("%s%s%s%s", V0, V1, V2, V3);

Is this the right/best (a stupid) way of doing it?
Title: Re: Concatenating string variable
Post by: RootBound on Sun 25/02/2024 17:09:30
Quote from: DeeKay on Sun 25/02/2024 13:50:53I managed to get it using string.format as follows:

L1.Text=String.Format("%s%s%s%s", V0, V1, V2, V3);

Is this the right/best (a stupid) way of doing it?

Don't know if it's the best way, but that's the way I do it.  :)
Title: Re: Concatenating string variable
Post by: Crimson Wizard on Sun 25/02/2024 18:14:11
Format is one way, another is Append:

Code (ags) Select
String s = "one";
s = s.Append("two");
s = s.Append("three");

Which to use is usually a matter of convenience, but I think that a single Format runs faster than multiple Appends, because each Append creates a new String copy.