【发布时间】:2015-02-27 14:19:31
【问题描述】:
我是 C# 新手,需要从文件中读取 float 值 (x, y, z)。
它看起来像:
0 -0.01 -0.002
0.000833333333333 -0.01 -0.002
如果我在尝试
float number = float.Parse("0,54"); // it works well, but
float number = float.Parse("0.54"); // gains exepction.
我从每一行读取值的代码(可能有问题):
int begin = 0;
int end = 0;
for (int i = 0; i < tempLine.Length; i++)
{
if (Char.IsWhiteSpace(tempLine.ElementAt(i)))
{
end = i;
float value = float.Parse(tempLine.Substring(begin, end));
begin = end;
System.Console.WriteLine(value);
}
}
有人可以帮忙吗?
【问题讨论】:
-
我会用空格分割字符串,然后用
float.Parse等循环数组
标签: c# .net string substring type-conversion