Hello,
Welcome to Microsoft Q&A!
I'm not sure about the input data that you mentioned. But I have made a solution about how to clean the second comma when user type something in the TextBox
. We could handle the TextBox.TextChanged Event and check the input value when user input every character. Then if we find that there are two commas, remove the last comma.
Here is the code I use:
private void MyTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
//remove the second comma
TextBox textBox = sender as TextBox;
string inputString = textBox.Text;
int count = Regex.Matches(inputString, ",").Count;
if (count > 1)
{
var lastIndex = inputString.LastIndexOf(",");
inputString= inputString.Remove(lastIndex, 1);
}
textBox.Text = inputString;
textBox.SelectionStart = textBox.Text.Length;
textBox.SelectionLength = 0;
var d = double.Parse(textBox.Text);
Debug.WriteLine(d);
}
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.