mercredi 6 juillet 2016

is there a way to replace string ">" with > in if condition

I come across a below use case but could not find proper solution. Is there a way to replace string "<" or ">" with condition < or > in if condition.

Ex:

  string condition = "<";
  if(10 condition 8)   //here I want to replace condition with < 
  {
      //some code
  }

I don't want to do like

if("<" == condition)
{
   if(10 < 8)
   {
   }
}
else if(">" == condition)
{
   if(10 > 10)
   {
   }
}

And my condition will change during a run time. I am just searching for a simple way if exist apart from above.

Use case : user will give some query like below

input : 10 > 9   =>  output : true
input : 10 < 7   =>  output  : false

basically I need to parse this query, as I have these 3 words (10, >, 9) as strings, some how I want to convert string ">" or "<" to actual symbol > or <.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire