我需要将字符串转换为整数。我的字符串可以是任何类型(浮点/整数/字符串/特殊字符)。
例如:
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);
我得到了错误:
输入字符串的格式不正确
我该如何转换它?