Adding two variables within a string

Back to topics list To post a new topic, please log in or register
avatar
4
marana77 2015.10.15 07:54
 

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. 

avatar
2017
gooly 2015.10.15 08:34 #
 

do you mean:

int a,b,c;
a = b = c = 7;


avatar
Moderator
3419
GumRai 2015.10.15 08:38 #
 

  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

avatar
736
honest_knave 2015.10.15 10:28 #
 

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

 

avatar
4
marana77 2015.10.15 12:18 #
 
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  

avatar
736
honest_knave 2015.10.15 12:35 #
 
   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));

 

avatar
126
Demos 2015.10.15 17:11 #
 

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 

Back to topics list  

To add comments, please log in or register