# Adding two variables within a string

16

Hi, can someone please let me know how I can add two assigned variables in a single sentence. i can do it with one e.g. "this is an example for a single", variable.

But how can I do the same but with two or more variables. Sorry if this seems like a newbie question but I have tried searching for the answer but to no avail. Im doing this for an alert function

Moderator
6868

do you mean:

```int a,b,c;
a = b = c = 7;```
Moderator
12393

```  string a="A=";
string b="B=";
string x="AxB=";
string p=", ";
int A=2;
int B=4;
int C=A*B;
string sentence=a+(string)A+p+b+(string)B+p+x+(string)C;
Print(sentence);```

I'm not sure that I understand correctly, but this may give you a pointer

Moderator
2302

Trying taking a look at StringFormat() / PrintFormat()

16

honest_knave:

Trying taking a look at StringFormat() / PrintFormat()

Thanks for the replies. Sorry if I wasn't clear before but what I mean is for instance

int A= 31

int B = 66

and I want to display an alert I would write

Alert("The value of variable A is ", A)

My question is how would I do the alert but display both A and B variables. I have tried something like

Alert("The value of variable A is ",A "and variable B is ",B)

but compiler returns an error.

Thanks

Moderator
2302

```   int    A=31;
int    B=66;
// Method 1
Alert("The value of A is "+(string)A+" and B is "+(string)B);
// Method 2
Alert(StringFormat("The value of A is %i and B is %i",A,B));
// Method 3
Alert(StringConcatenate("The value of A is ",A," and B is ",B));```
236

marana77:

Alert("The value of variable A is ",A "and variable B is ",B)

hello,

you have to put a comma after A

best regards