我有这样的字符串:
string line = "77.139305\t28.795975"
然后我像这样分开两个整数:
string lat = line.Substring(0, 9);
string lng = line.Substring(10, 9);
这两个数字完全分开,如下所示:
“77.139305”
和 “28.795975”
用于纬度和经度。
int latitude,longitude;
bool result = Int32.TryParse(lat, out latitude);
if (result)
{
col1[i] = latitude;
Console.WriteLine("lat: " + col1[i]);
}
else
{
if (lat == null) lat = "";
Console.WriteLine("Attempted conversion of lat '{0}' failed.", lat);
}
bool result2 = Int32.TryParse(lng, out longitude);
if (result2)
{
col2[i] = longitude;
Console.WriteLine("longit: " + col2[i]);
}
else
{
if (lng == null) lng = "";
Console.WriteLine("Attempted conversion of lng '{0}' failed.", lng);
}
结果它总是执行其他条件,如果我不在其他条件下处理这个异常,那么它会给出“输入字符串在 c# net int.parse 中的格式不正确” 如何解决这个问题?
最佳答案
您正在传递 float 并使用整数解析方法。
使用 Double.Parse
解析方法。
关于c# - 在 c# net int.parse 中,输入字符串的格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30435224/