Tag Archives: parsing

Convert an integer into an ordinal (1st, 2nd, 3rd) in C#

This example uses the following int extension method to convert an integer into an ordinal. The method returns an integer’s ordinal suffix, as in “rd” fo rthe value i1103, so you can make 1103rd or 1,103rd. // Return the int’s … Continue reading

Posted in parsing, strings | Tagged , , , , , , , , , , , , , , | 1 Comment

Replace text in the lines of a string in C#

This example uses the following code to replace text in the lines of a string. private void btnGo_Click(object sender, EventArgs e) { try { Regex reg_exp = new Regex(txtPattern.Text); lblResult.Text = reg_exp.Replace( txtInput.Text, txtReplacementPattern.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); … Continue reading

Posted in regular expressions, strings | Tagged , , , , , , , , , , , , | 6 Comments

Convert bases decimal, hexadecimal, octal, and binary in C#

It’s easy to convert bases if you use the Convert class’s ToInt64 and ToString methods. For example, the following statement parses the text in the TextBox named source and saves the result in the long variable value. The “16” means … Continue reading

Posted in mathematics, parsing | Tagged , , , , , , , , , , , | 6 Comments

Parse currency values in C#

Converting a decimal value into a currency formatted string is easy. Simply use its ToString method, passing it the parameter “C” as in the following code. txtAny.Text = value.ToString(“C”); Strangely parsing a currency value entered by the user is not … Continue reading

Posted in parsing, syntax | Tagged , , , , , , , , , , | Leave a comment