我试图阻止我的进程挂起,因为它看到csv文件中的错误,通常是“#N / A”,其中应该有一个double(我在读入时知道它的字符串... )
但这不起作用,为什么?
String ColumnString = (values[Column]);
String NA = "#N/A";
if (ColumnString==NA);
{
Console.WriteLine(values[Column]);
Console.WriteLine("non numeric value detected, Skipping line #{0}", LineNumber);
break;
}
答案 0 :(得分:0)
如果你确定ColumnString的类型是字符串,你可以检查它至少有一个数字字符,如下面的linq查询
bool hasnumeric = ColumnString.Any(t => char.IsNumber(t));
if(hasnumeric== true)
{
//colomnString has at least one numeric character
}else{
//colomnString doesn't have any numeric characters
}
答案 1 :(得分:0)
string ColumnString = (values[Column]);
string NA = "#N/A";
if (string.Compare(ColumnString,NA)==0)
{
Console.WriteLine(values[Column]);
Console.WriteLine("non numeric value detected, Skipping line #{0}", LineNumber);
break;
}