Let's say the input string is: 1234*(5600-230.831)+1234.56/8456123*25%
The output string needs to have commas added: 1,234*(5,600-230.831)+1,234.56/8,456,123*25%
I have this so far for simple numbers. But is there some way to make it work with complex equations as shown in above example?
private void TextBoxEquation_TextChanging(TextBox sender, TextBoxTextChangingEventArgs args)
{
try
{
int selectionIndex = textBoxEquation.SelectionStart;
string simpleNum = textBoxEquation.Text.Replace(",", "");
var value = string.Format("{0:N0}", long.Parse(simpleNum));
textBoxEquation.Text = value;
textBoxEquation.SelectionStart = selectionIndex + 1;
}
catch { }
}
Basically, as the user types in the equation, the relevant commas need to be added automatically.