parse int to string
public class Solution { public int StrToInt(string str) { if (string.IsNullOrEmpty(str)) return 0; var sign = str[0] == '+' || str[0] == '-' ? 1 : 0; long result = 0; for (int i = sign; i < str.Length; i++) { if (!Char.IsDigit(str[i])) return 0; result = result * 10 + (str[i] - '0'); if (sign == 1 && str[0] == '-') result = -result; if (result > Int32.MaxValue) return 0; if (result < Int32.MinValue) return 0; } return (int)result; } }