public void signChange() { bool anyOperators = false; bool positiveSign = true; int index = 0; string x = ""; if (OperationDisplay.Length != 0 && !(OperationDisplay.LastIndexOfAny(operators.ToArray()) == OperationDisplay.Length - 1)) { for (int i = 0; i < 4; i++) { if (OperationDisplay.Contains(operators[i])) { anyOperators = true; } } if (anyOperators) { index = OperationDisplay.LastIndexOfAny(operators.ToArray()); } if (anyOperators && OperationDisplay.Substring(index - 1).Contains('(')) { positiveSign = false; } if (positiveSign) { if (index != 0) { x = OperationDisplay.Substring(index + 1); } else { x = OperationDisplay; } x = "(-" + x + ')'; if (index != 0) { OperationDisplay = OperationDisplay.Remove(index + 1); OperationDisplay += x; } else { OperationDisplay = x; } } else { x = OperationDisplay.Substring(index - 1); x = x.Trim('(', ')'); x = x.Trim('-'); OperationDisplay = OperationDisplay.Remove(index - 1); OperationDisplay += x; } } }
public bool isNegative() { int index_oprtr = OperationDisplay.LastIndexOfAny(operators.ToArray()); int index_bracket = OperationDisplay.LastIndexOf('('); if (index_oprtr == index_bracket + 1) { return(true); } return(false); }
public void noWrongDots() { if (((OperationDisplay.LastIndexOf('.') < OperationDisplay.LastIndexOfAny(operators.ToArray())) || (!OperationDisplay.Contains('.'))) && OperationDisplay != "") { if (OperationDisplay.LastIndexOf(')') == OperationDisplay.Length - 1) { OperationDisplay = OperationDisplay.Insert(OperationDisplay.Length - 1, "."); } else if (OperationDisplay.LastIndexOfAny(operators.ToArray()) != OperationDisplay.Length - 1) { OperationDisplay += '.'; } } }
public bool noDoubleOperators() { if (OperationDisplay.LastIndexOfAny(operators.ToArray()) == OperationDisplay.Length - 1) { OperationDisplay = OperationDisplay.Trim(operators.ToArray()); } bool anyPreviousOperations = false; for (int i = 0; i < 4; i++) { if (OperationDisplay.Contains(operators[i])) { anyPreviousOperations = true; } } return(anyPreviousOperations); }