Two character Integer to char?Comparing two byte arrays in .NETHow can I decode HTML characters in C#?Best way to repeat a character in C#What do two question marks together mean in C#?How would you count occurrences of a string (actually a char) within a string?C# convert integer to hex and back again.NET / C# - Convert char[] to stringCalculate difference between two dates (number of days)?Simple problem with replacing string value C#Change specific characters in large string array

Responsibility for visa checking

What flavor of zksnark in tezos

Linux tr to convert vertical text to horizontal

Is it OK to bring delicacies from hometown as tokens of gratitude for an out-of-town interview?

Is it possible for people to live in the eye of a permanent hypercane?

How to make thick Asian sauces?

Pros and cons of writing a book review?

Old black and white movie: glowing black rocks slowly turn you into stone upon touch

Can Green-Flame Blade be cast twice with the Hunter ranger's Horde Breaker ability?

Do I include animal companions when calculating difficulty of an encounter?

I completed a difficult task using a tool I developed before joining my employer. What is my obligation?

How could a possessed body begin to rot and decay while it is still alive?

What's the most polite way to tell a manager "shut up and let me work"?

Secure offsite backup, even in the case of hacker root access

Credit card offering 0.5 miles for every cent rounded up. Too good to be true?

3 as a Sum of 3 Pan Digital Expressions

Bent spoke design wheels — feasible?

How to search all Apex Classes in IntelliJ Illuminated Cloud?

Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?

It possible to have subscript and super script that does not shrink the font size?

What are the words for people who cause trouble believing they know better?

Convert camelCase and PascalCase to Title Case

California: "For quality assurance, this phone call is being recorded"

Can a magnetic field of an object be stronger than its gravity?



Two character Integer to char?


Comparing two byte arrays in .NETHow can I decode HTML characters in C#?Best way to repeat a character in C#What do two question marks together mean in C#?How would you count occurrences of a string (actually a char) within a string?C# convert integer to hex and back again.NET / C# - Convert char[] to stringCalculate difference between two dates (number of days)?Simple problem with replacing string value C#Change specific characters in large string array






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















So I am making a program that calculates X in an expression, e.g if I type 2*x=6 then it will say x = 3.
My code:



 string[] exps = textBox1.Text.Split('=');
DataTable dt = new DataTable();
for (int i = 0; i < 50; i++)

string s = exps[0].Replace('x', Convert.ToChar(i.ToString())); //<- problem is there
var v = dt.Compute(s, "");
if (int.Parse(v.ToString()) == int.Parse(exps[1]))

listBox1.Items.Add("x = " + i);
break;




But I have a problem when X is more than 9 (so it is two characters) e.g 12 or 27, It can't convert it to char. Can you help me how can I do this easier? Thank you!



And sorry for my bad English










share|improve this question




























    3















    So I am making a program that calculates X in an expression, e.g if I type 2*x=6 then it will say x = 3.
    My code:



     string[] exps = textBox1.Text.Split('=');
    DataTable dt = new DataTable();
    for (int i = 0; i < 50; i++)

    string s = exps[0].Replace('x', Convert.ToChar(i.ToString())); //<- problem is there
    var v = dt.Compute(s, "");
    if (int.Parse(v.ToString()) == int.Parse(exps[1]))

    listBox1.Items.Add("x = " + i);
    break;




    But I have a problem when X is more than 9 (so it is two characters) e.g 12 or 27, It can't convert it to char. Can you help me how can I do this easier? Thank you!



    And sorry for my bad English










    share|improve this question
























      3












      3








      3








      So I am making a program that calculates X in an expression, e.g if I type 2*x=6 then it will say x = 3.
      My code:



       string[] exps = textBox1.Text.Split('=');
      DataTable dt = new DataTable();
      for (int i = 0; i < 50; i++)

      string s = exps[0].Replace('x', Convert.ToChar(i.ToString())); //<- problem is there
      var v = dt.Compute(s, "");
      if (int.Parse(v.ToString()) == int.Parse(exps[1]))

      listBox1.Items.Add("x = " + i);
      break;




      But I have a problem when X is more than 9 (so it is two characters) e.g 12 or 27, It can't convert it to char. Can you help me how can I do this easier? Thank you!



      And sorry for my bad English










      share|improve this question














      So I am making a program that calculates X in an expression, e.g if I type 2*x=6 then it will say x = 3.
      My code:



       string[] exps = textBox1.Text.Split('=');
      DataTable dt = new DataTable();
      for (int i = 0; i < 50; i++)

      string s = exps[0].Replace('x', Convert.ToChar(i.ToString())); //<- problem is there
      var v = dt.Compute(s, "");
      if (int.Parse(v.ToString()) == int.Parse(exps[1]))

      listBox1.Items.Add("x = " + i);
      break;




      But I have a problem when X is more than 9 (so it is two characters) e.g 12 or 27, It can't convert it to char. Can you help me how can I do this easier? Thank you!



      And sorry for my bad English







      c#






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 13:27









      SchollerScholler

      365




      365






















          3 Answers
          3






          active

          oldest

          votes


















          6














          You don't have to use the Replace(char, char) overload. There is also a Replace(string, string) overload:



          string s = exps[0].Replace("x", i.ToString());


          You are probably aware of this already, but your way of solving equations only works for a very specific kind of equations. Mainly it has these problems:



          • the solution must be an integer between 0 and 49

          • there must be only one solution

          • Multiplication must be clearly indicated i.e. 5x doesn't mean 5 times x.

          • The right hand side must be an integer. This problem can be easily fixed by calling Compute with exps[1] (with the x substitutes in of course).





          share|improve this answer

























          • Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

            – Scholler
            Mar 24 at 14:25











          • @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

            – Sweeper
            Mar 24 at 14:33


















          2














          Instead of char just convert it to string:



          exps[0].Replace("x", i.ToString());





          share|improve this answer






























            1














            You can create a datatable with two columns



            (1) with column name 'X', this will keep value and



            (2) a Computed column which will have expression.



            Sample Code:



             var dt=new DataTable();
            dt.Columns.Add(new DataColumn("X", typeof(float)));

            var exprCol=new DataColumn("Expr");
            exprCol.Expression="X+10";

            dt.Columns.Add(exprCol);

            var row = dt.NewRow();
            row["X"] = 5;
            dt.Rows.Add(row);
            var calculatedValue=row["Expr"];





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324270%2ftwo-character-integer-to-char%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              6














              You don't have to use the Replace(char, char) overload. There is also a Replace(string, string) overload:



              string s = exps[0].Replace("x", i.ToString());


              You are probably aware of this already, but your way of solving equations only works for a very specific kind of equations. Mainly it has these problems:



              • the solution must be an integer between 0 and 49

              • there must be only one solution

              • Multiplication must be clearly indicated i.e. 5x doesn't mean 5 times x.

              • The right hand side must be an integer. This problem can be easily fixed by calling Compute with exps[1] (with the x substitutes in of course).





              share|improve this answer

























              • Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

                – Scholler
                Mar 24 at 14:25











              • @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

                – Sweeper
                Mar 24 at 14:33















              6














              You don't have to use the Replace(char, char) overload. There is also a Replace(string, string) overload:



              string s = exps[0].Replace("x", i.ToString());


              You are probably aware of this already, but your way of solving equations only works for a very specific kind of equations. Mainly it has these problems:



              • the solution must be an integer between 0 and 49

              • there must be only one solution

              • Multiplication must be clearly indicated i.e. 5x doesn't mean 5 times x.

              • The right hand side must be an integer. This problem can be easily fixed by calling Compute with exps[1] (with the x substitutes in of course).





              share|improve this answer

























              • Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

                – Scholler
                Mar 24 at 14:25











              • @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

                – Sweeper
                Mar 24 at 14:33













              6












              6








              6







              You don't have to use the Replace(char, char) overload. There is also a Replace(string, string) overload:



              string s = exps[0].Replace("x", i.ToString());


              You are probably aware of this already, but your way of solving equations only works for a very specific kind of equations. Mainly it has these problems:



              • the solution must be an integer between 0 and 49

              • there must be only one solution

              • Multiplication must be clearly indicated i.e. 5x doesn't mean 5 times x.

              • The right hand side must be an integer. This problem can be easily fixed by calling Compute with exps[1] (with the x substitutes in of course).





              share|improve this answer















              You don't have to use the Replace(char, char) overload. There is also a Replace(string, string) overload:



              string s = exps[0].Replace("x", i.ToString());


              You are probably aware of this already, but your way of solving equations only works for a very specific kind of equations. Mainly it has these problems:



              • the solution must be an integer between 0 and 49

              • there must be only one solution

              • Multiplication must be clearly indicated i.e. 5x doesn't mean 5 times x.

              • The right hand side must be an integer. This problem can be easily fixed by calling Compute with exps[1] (with the x substitutes in of course).






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 24 at 14:04

























              answered Mar 24 at 13:31









              SweeperSweeper

              76.8k1176148




              76.8k1176148












              • Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

                – Scholler
                Mar 24 at 14:25











              • @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

                – Sweeper
                Mar 24 at 14:33

















              • Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

                – Scholler
                Mar 24 at 14:25











              • @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

                – Sweeper
                Mar 24 at 14:33
















              Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

              – Scholler
              Mar 24 at 14:25





              Can you explain me how can I make it with float numbers, e.g 5.10+x=5.20 ?

              – Scholler
              Mar 24 at 14:25













              @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

              – Sweeper
              Mar 24 at 14:33





              @Scholler then you can’t use your current method - trying a bunch of values and see which works. You probably need some kind of algorithm to rearrange the equation. The problem becomes much much harder.

              – Sweeper
              Mar 24 at 14:33













              2














              Instead of char just convert it to string:



              exps[0].Replace("x", i.ToString());





              share|improve this answer



























                2














                Instead of char just convert it to string:



                exps[0].Replace("x", i.ToString());





                share|improve this answer

























                  2












                  2








                  2







                  Instead of char just convert it to string:



                  exps[0].Replace("x", i.ToString());





                  share|improve this answer













                  Instead of char just convert it to string:



                  exps[0].Replace("x", i.ToString());






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 13:32









                  Ashkan Mobayen KhiabaniAshkan Mobayen Khiabani

                  23.7k1968125




                  23.7k1968125





















                      1














                      You can create a datatable with two columns



                      (1) with column name 'X', this will keep value and



                      (2) a Computed column which will have expression.



                      Sample Code:



                       var dt=new DataTable();
                      dt.Columns.Add(new DataColumn("X", typeof(float)));

                      var exprCol=new DataColumn("Expr");
                      exprCol.Expression="X+10";

                      dt.Columns.Add(exprCol);

                      var row = dt.NewRow();
                      row["X"] = 5;
                      dt.Rows.Add(row);
                      var calculatedValue=row["Expr"];





                      share|improve this answer



























                        1














                        You can create a datatable with two columns



                        (1) with column name 'X', this will keep value and



                        (2) a Computed column which will have expression.



                        Sample Code:



                         var dt=new DataTable();
                        dt.Columns.Add(new DataColumn("X", typeof(float)));

                        var exprCol=new DataColumn("Expr");
                        exprCol.Expression="X+10";

                        dt.Columns.Add(exprCol);

                        var row = dt.NewRow();
                        row["X"] = 5;
                        dt.Rows.Add(row);
                        var calculatedValue=row["Expr"];





                        share|improve this answer

























                          1












                          1








                          1







                          You can create a datatable with two columns



                          (1) with column name 'X', this will keep value and



                          (2) a Computed column which will have expression.



                          Sample Code:



                           var dt=new DataTable();
                          dt.Columns.Add(new DataColumn("X", typeof(float)));

                          var exprCol=new DataColumn("Expr");
                          exprCol.Expression="X+10";

                          dt.Columns.Add(exprCol);

                          var row = dt.NewRow();
                          row["X"] = 5;
                          dt.Rows.Add(row);
                          var calculatedValue=row["Expr"];





                          share|improve this answer













                          You can create a datatable with two columns



                          (1) with column name 'X', this will keep value and



                          (2) a Computed column which will have expression.



                          Sample Code:



                           var dt=new DataTable();
                          dt.Columns.Add(new DataColumn("X", typeof(float)));

                          var exprCol=new DataColumn("Expr");
                          exprCol.Expression="X+10";

                          dt.Columns.Add(exprCol);

                          var row = dt.NewRow();
                          row["X"] = 5;
                          dt.Rows.Add(row);
                          var calculatedValue=row["Expr"];






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 24 at 17:15









                          Amit KumarAmit Kumar

                          1498




                          1498



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324270%2ftwo-character-integer-to-char%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해