private void txtInput_TextChanged(object sender, System.EventArgs e) { TimeSpan ts; try { string s = this.txtInput.Text; if (s.ToLower().IndexOf("min") > 0) { int i = s.ToLower().IndexOf("min"); string temp = s.Substring(0, i); int number = Int32.Parse(temp); ts = new TimeSpan(0, number, 0); } else { ts = TimeSpan.Parse(s); } duration = ts; this.lblDuration.Text = ts.ToString(); btnRecord.Enabled = true; } catch { duration = new TimeSpan(0); lblDuration.Text = "Not understood"; btnRecord.Enabled = false; } }
public static int B_ToNumber(ILuaState lua) { LuaType t = lua.Type(2); if (t == LuaType.LUA_TNONE || t == LuaType.LUA_TNIL) // standard conversion { bool isnum; double n = lua.ToNumberX(1, out isnum); if (isnum) { lua.PushNumber(n); return(1); } // else not a number; must be something lua.L_CheckAny(1); } else { string s = lua.L_CheckString(1); int numBase = lua.L_CheckInteger(2); bool negative = false; lua.L_ArgCheck((2 <= numBase && numBase <= 36), 2, "base out of range"); s = s.Trim(' ', '\f', '\n', '\r', '\t', '\v'); s = s + '\0'; // guard int pos = 0; if (s[pos] == '-') { pos++; negative = true; } else if (s[pos] == '+') { pos++; } if (Char.IsLetterOrDigit(s, pos)) { double n = 0.0; do { int digit; if (Char.IsDigit(s, pos)) { digit = Int32.Parse(s[pos].ToString()); } else { digit = Char.ToUpper(s[pos]) - 'A' + 10; } if (digit >= numBase) { break; // invalid numeral; force a fail } n = n * (double)numBase + (double)digit; pos++; } while(Char.IsLetterOrDigit(s, pos)); if (pos == s.Length - 1) // except guard, no invalid trailing characters? { lua.PushNumber(negative ? -n : n); return(1); } // else not a number } // else not a number } lua.PushNil(); // not a number return(1); }