I have two text boxes, one for the input and another for the output. I need to filter only Hexadecimals characters from input and output it in uppercase. I have checked that using Regular Expressions (Regex
) is much faster than using loop.
My current code to uppercase first then filter the Hex digits as follow:
string strOut = Regex.Replace(inputTextBox.Text.ToUpper(), "[^0-9^A-F]", "");
outputTextBox.Text = strOut;
An alternatively:
string strOut = Regex.Replace(inputTextBox.Text, "[^0-9^A-F^a-f]", "");
outputTextBox.Text = strOut.ToUpper();
The input may contain up to 32k characters, therefore speed is important here. I have used TimeSpan
to measure but the results are not consistent.
My question is: which code has better speed performance and why?