Adding two variables within a string

 

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

Thanks in advance. 

 

do you mean:

int a,b,c;
a = b = c = 7;
 
  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

 

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

 
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  

 
   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));
 

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 

Reason: