| | |
Math output
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Okay, the FormatText function works, i wrote and tested it in a seperate app. Can you use a breakpoint and tell me what the input is at the start of the method and what it is at the end please.
Also, go line by line to see where it is hanging.
Also, go line by line to see where it is hanging.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Ignore last post...thread hadnt updated to show your last message 
Glad you got it working. Took some doing but we got there

Glad you got it working. Took some doing but we got there
Last edited by Ryshad; Oct 5th, 2009 at 10:57 am.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: Jul 2009
Posts: 117
Reputation:
Solved Threads: 10
0
#53 24 Days Ago
For finding nth root , latex format is "\sqrt[]{}" and on button click the form which displays in textbox is : "root:[]{}" . Now to convert this "root:[]{}" into latex format i am using following code :
And I using this code just after the fraction code.
But this code is not giving desired result .
Kindly help me out..........
C# Syntax (Toggle Plain Text)
const string matchNumerator1 = @"root:\((?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)"; const string matchDenominator1 = @"\((?<Denominator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)"; const string matchBoth1 = matchNumerator1 + matchDenominator1; System.Text.RegularExpressions.Match n = System.Text.RegularExpressions.Regex.Match(input, matchBoth1); while (n.Success) { string sNumerator1 = n.Groups["Numerator4"].Value; string sDenominator2 = n.Groups["Denominator4"].Value; string latex1 = @"\sqrt[" + sNumerator1.ToString() + "]{" + sDenominator2.ToString() + "}"; input = input.Remove(n.Index, n.Length); input = input.Insert(n.Index, latex1); n = System.Text.RegularExpressions.Regex.Match(input, matchBoth1); }
And I using this code just after the fraction code.
But this code is not giving desired result .
Kindly help me out..........
Last edited by vinnijain; 24 Days Ago at 8:55 am.
2
#54 24 Days Ago
Of course it isnt working; you told me the format was
so thats what it is looking for.
the above code will find the string you need.
Once again, i cannot understate the importance of learning what the code is doing. The numerator and denimonator code hasnt changed at all from the fraction regex. All that has changed is the enclosing parentheses.
\((?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)
root:\[(?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]
You could have easily changed the symbols yourself. I'm not trying to rant or condescend but, if you are trying to learn how to code, these are the kind of problems you will face all the time and learning how to overcome them yourself will make you a much stronger programmer. Every time you encounter new syntax, or a structure you havent used before, experiment with it, read the documentation for it, disect it. You need to understand exactly what its doing so that you can adapt it for future problems. The same goes for code that you are given in forums. We will gladly help you out and provide you with code, but its SO important that you dont just copy and paste the code and move on...learn why the code you are given works. Look at how it has been structured so that you can learn how other coders solve problems.
C# Syntax (Toggle Plain Text)
const string matchNumerator1 = @"root:\[(?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]"; const string matchDenominator1 = @"\{(?<Denominator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\}";
the above code will find the string you need.
Once again, i cannot understate the importance of learning what the code is doing. The numerator and denimonator code hasnt changed at all from the fraction regex. All that has changed is the enclosing parentheses.
\((?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)
root:\[(?<Numerator4>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]
You could have easily changed the symbols yourself. I'm not trying to rant or condescend but, if you are trying to learn how to code, these are the kind of problems you will face all the time and learning how to overcome them yourself will make you a much stronger programmer. Every time you encounter new syntax, or a structure you havent used before, experiment with it, read the documentation for it, disect it. You need to understand exactly what its doing so that you can adapt it for future problems. The same goes for code that you are given in forums. We will gladly help you out and provide you with code, but its SO important that you dont just copy and paste the code and move on...learn why the code you are given works. Look at how it has been structured so that you can learn how other coders solve problems.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
0
#56 23 Days Ago
•
•
•
•
Thanks for replying ........
This I have already done.......but problem is that it is not working when I am trying to enter fraction...........
I don't what's the problem............
Have you added the code i gave you for powers, or have you replaced the old code with the new?
The old code replace fractions, the new code replaces powers. You need to have both. If you have implemented both correctly it will work fine for fractions within powers and vice versa:
C# Syntax (Toggle Plain Text)
private void button1_Click(object sender, EventArgs e) { textBox2.Text = FormatText(textBoxEquation.Text); } private string FormatText(string input) { input = ReplaceFrac(input); input = ReplacePowers(input); return input; } private string ReplaceFrac(string input) { const string matchNumerator = @"\((?<Numerator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)"; const string matchDenominator = @"\((?<Denominator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\)"; const string matchBoth = matchNumerator + @"\/" + matchDenominator; System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); while (m.Success) { string dNumerator = m.Groups["Numerator"].Value; string dDenominator = m.Groups["Denominator"].Value; string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}"; input = input.Remove(m.Index, m.Length); input = input.Insert(m.Index, latex); m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); } return input; } private string ReplacePowers(string input) { const string matchNumerator = @"root:\[(?<Numerator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\]"; const string matchDenominator = @"\{(?<Denominator>((?<p>\()|[^\(\)]|(?(p)(?<-p>\))|))*)\}"; const string matchBoth = matchNumerator + matchDenominator; System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); while (m.Success) { string dNumerator = m.Groups["Numerator"].Value; string dDenominator = m.Groups["Denominator"].Value; string latex = @"\sqrt [" + dNumerator.ToString() + "]{" + dDenominator.ToString() + "}"; input = input.Remove(m.Index, m.Length); input = input.Insert(m.Index, latex); m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); } return input; }
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: Jul 2009
Posts: 117
Reputation:
Solved Threads: 10
0
#57 23 Days Ago
Thanks a lot Ryshad...........
It works............
I hav'nt removed the code but the mistake which I have done was that I added both codes one after the another instead of making functions and the calling those functions.................
I understood my mistake..........
Now the code works fine......................
Thanks once again...............
It works............
I hav'nt removed the code but the mistake which I have done was that I added both codes one after the another instead of making functions and the calling those functions.................
I understood my mistake..........
Now the code works fine......................
Thanks once again...............
0
#58 23 Days Ago
•
•
•
•
Thanks a lot Ryshad...........
It works............
I hav'nt removed the code but the mistake which I have done was that I added both codes one after the another instead of making functions and the calling those functions.................
I understood my mistake..........
Now the code works fine......................
Thanks once again...............
I just moved them to methods to make the code tidier/more readable/easier to maintain. Also, the regex variables are declared as const so you cant change them so if you wanted both pieces of code in the main method you would need to declare new variables for the new regex

Either way, glad it all works for ya...remember to mark the thread as solved and turn out the lights when you leave
Last edited by Ryshad; 23 Days Ago at 6:52 am.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
0
#59 23 Days Ago
•
•
•
•
I added both codes one after the another instead of making functions and the calling those functions
Many people (including myself on occasion) misuse the terms, so i thought i'd just throw this in to try and un-muddy the waters of c# jargon :p
Last edited by Ryshad; 23 Days Ago at 6:53 am.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
![]() |
Similar Threads
- how to use regex or an array to display some output from an arithmetic input? (VB.NET)
- Trouble with area (Java)
- math help (PHP)
- math program (C)
- Math.max prob???...XD (Java)
- So Stuck (C++)
- Assigning Array Values En Masse (Java)
- Output in Text file-How to apply fprintf()? (C)
- Output in the text file (C)
- missing function header (C++)
Other Threads in the C# Forum
- Previous Thread: How to generate button at runtime and its text from database for windows application
- Next Thread: password setting in a software
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom customactiondata database datagrid datagridview dataset date/time datetime datetimepicker degrees development dll draganddrop drawing encryption enum event excel file filename files form format forms function gdi+ gis gtk hash httpwebrequest image index input install java label list listbox mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remote remoting richtextbox server sleep socket sql statistics stream string table tables tcp text textbox thread time timer tutorial update usercontrol usercontrols validation visualstudio webbrowser webcam wia windows winforms wpf xml





