Concatenating string variable

Started by DeeKay, Sun 25/02/2024 13:50:53

Previous topic - Next topic

DeeKay

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?

RootBound

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.  :)
They/them. Here are some of my games:

Crimson Wizard

Format is one way, another is Append:

Code: ags
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.

SMF spam blocked by CleanTalk