我需要一个字符串转换为整型。我的字符串可以是任何类型(float/int/string /特殊字符)。将字符串转换为整数,在C#/。NET
例如:
If my string is "2.3", I need to convert to = 2
If my string is "anyCharacter", I need to convert to = 0
If my string is "2", I need to convert to = 2
我试过如下:
string a = "1.25";int b = Convert.ToInt32(a);
我得到了错误:
Input string was not in a correct format
如何转换呢?
@K D谢谢:-) – 2013-02-28 09:05:11