private void ParseAndAdd(string message) { Console.ForegroundColor = ConsoleColor.White; var sIndex = message.IndexOf('S'); var xIndex = message.IndexOf('X'); var yIndex = message.IndexOf('Y'); var zIndex = message.IndexOf('Z'); var eIndex = message.IndexOf('E'); if (sIndex != -1 && xIndex != -1 && yIndex != -1 && zIndex != -1 && eIndex != -1) { int tempInt, sensor = 0; float tempFloat, xValue, yValue, zValue = 0; if (!int.TryParse(message.Substring(sIndex + 1, xIndex - sIndex - 1), out tempInt)) { return; } sensor = tempInt; if (!float.TryParse(message.Substring(xIndex + 1, yIndex - xIndex - 1), out tempFloat)) { return; } xValue = tempFloat; if (!float.TryParse(message.Substring(yIndex + 1, zIndex - yIndex - 1), out tempFloat)) { return; } yValue = tempFloat; if (!float.TryParse(message.Substring(zIndex + 1, eIndex - zIndex - 1), out tempFloat)) { return; } zValue = tempFloat; Console.WriteLine(message); if (sensor == 1 || sensor == 5) { _snap.Change(sensor, yValue); } //else if (sensor == 3 || sensor == 4) _snap.Change(sensor, zValue); else { _snap.Change(sensor, xValue); } } }