I have to eliminate all special characters, alphabets and keep only the numbers in the string and store it into an integer. For example "$67%!" or "$127a%". I am obtaining data from serial port and in certain cases there are alphabets/ special chars between $ and % or may be a number after %. Currently, I have this snippet with me
string UartInput = serialcom.ReadLine();
int[] ints = UartInput.Trim(new[] { '$', '%' }).Split(' ').Select(int.Parse).ToArray();
I made a few needed changes and transmitted a single value at a time. The snippet was changed to
int ints = Convert.ToInt16(serialcom.ReadLine().Trim(new[] { '$', '%' }))
It was insufficient