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;
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#
add a comment |
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#
add a comment |
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#
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#
c#
asked Mar 24 at 13:27
SchollerScholler
365
365
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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.
5xdoesn't mean 5 times x. - The right hand side must be an integer. This problem can be easily fixed by calling
Computewithexps[1](with thexsubstitutes in of course).
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
add a comment |
Instead of char just convert it to string:
exps[0].Replace("x", i.ToString());
add a comment |
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"];
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
5xdoesn't mean 5 times x. - The right hand side must be an integer. This problem can be easily fixed by calling
Computewithexps[1](with thexsubstitutes in of course).
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
add a comment |
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.
5xdoesn't mean 5 times x. - The right hand side must be an integer. This problem can be easily fixed by calling
Computewithexps[1](with thexsubstitutes in of course).
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
add a comment |
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.
5xdoesn't mean 5 times x. - The right hand side must be an integer. This problem can be easily fixed by calling
Computewithexps[1](with thexsubstitutes in of course).
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.
5xdoesn't mean 5 times x. - The right hand side must be an integer. This problem can be easily fixed by calling
Computewithexps[1](with thexsubstitutes in of course).
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
add a comment |
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
add a comment |
Instead of char just convert it to string:
exps[0].Replace("x", i.ToString());
add a comment |
Instead of char just convert it to string:
exps[0].Replace("x", i.ToString());
add a comment |
Instead of char just convert it to string:
exps[0].Replace("x", i.ToString());
Instead of char just convert it to string:
exps[0].Replace("x", i.ToString());
answered Mar 24 at 13:32
Ashkan Mobayen KhiabaniAshkan Mobayen Khiabani
23.7k1968125
23.7k1968125
add a comment |
add a comment |
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"];
add a comment |
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"];
add a comment |
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"];
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"];
answered Mar 24 at 17:15
Amit KumarAmit Kumar
1498
1498
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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