我在后台调用了前台js函数,获取了hidden的value值,但是我想将它转换成int类型,但是却提示:输入的字符串的格式不正确。下面两种办法我都试过了,不行。
int.Parse(Hidden11.Value);
Convert.ToInt32(Hidden11.Value);
大侠们有什么好的解决办法没?
------解决方案--------------------------------------------------------
Hidden11.Value.Tostring()+"1",你这样拼接后。然后在转换,看能转换成功不?
如果能。证明1024不能转换把!如果不能。那就是有问题咯!
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
- C# code
public static int StrToInt(string str, int defValue) { if (str == null) return defValue; if (str.Length > 0 && str.Length <= 11 && Regex.IsMatch(str, @"^[-]?[0-9]*$")) { if ((str.Length < 10) || (str.Length == 10 && str[0] == '1') || (str.Length == 11 && str[0] == '-' && str[1] == '1')) { return Convert.ToInt32(str); } } return defValue; }