Tuesday, 8 April 2014

c# Parsing strings controlling Expressions

I have a following formula in a Windows C# form that parses a textbox
string. The customary twine would feeling something like: z5 100c x87.50.
Another instance competence be:m5 100c vs z5 100c. In both examples, we
have several attributes that are important, "z5', "100", "c", "x",
"87.50". From this twine we am feeding it into several functions (these
functions are reduction important). we found several samples and have a
next code, though when we run a formula it will wholly parse a initial
found countenance and not iterate by and arrangement all found
expressions. For example, "z5 100c x87.50" advantage 5 and c. Is there a
improved slight for reading a whole string, afterwards parsing and
extracting a applicable information?private vacant
toolStripButton2_Click(object sender, EventArgs e){ twine agreement =
toolStripTextBox1.ToString(); twine contractConvert =
contract.ToLower(); Regex re = new
Regex("c$\\.?|p$\\.?|s$\\.?|f$\\.?|cs\\.?|ps\\.?|vs\\.?|x\\.?"); Regex
rePrice = new Regex("[0-9]{1,4}(\\.[0-9]{1,2})?"); Match m =
re.Match(contractConvert.ToString()); Match mPrice =
rePrice.Match(contract.ToString()); if (m.Success) {
MessageBox.Show(string.Format("Structure: " + m.Value)); } else {
MessageBox.Show("Structure incorrect!"); } if
(mPrice.Success) { MessageBox.Show(string.Format("Strike: " +
mPrice.Value)); } else { MessageBox.Show("Structure
incorrect! Requires a strike."); }}

No comments:

Post a Comment