[英]Isolating a float value in a .csv file
我偶然发现了一个小编码问题。 我想读取一个.csv 文件并将其数据处理为浮点数(用于更改对象的某些参数),因此我可以单独使用.csv 文件中的任何一个数字。 此时我的代码可以读取 .csv 文件,但我无法将每个数字都处理为浮点数。 如何使用从 a.csv 中隔离一个值以便稍后在程序中使用它? 我使用的数据文件有 4 行 100 行。 我此时的代码是这样的(它只能从.csv文件中读取数据):
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; public class mag_rotation : MonoBehaviour { // Start is called before the first frame update void Start() { ReadCSVFile(); } void ReadCSVFile() { StreamReader strReader = new StreamReader("D:200119200120.csv"); bool endOfFile = false; while(!endOfFile) { string data_String = strReader.ReadLine(); if (data_String == null) { endOfFile = true; break; } var data_values = data_String.Split (','); } } void Update() { } }
例如,从以下数据:
0,17.02241,-4.793719,4.5759873,0
1,17.394623,-4.112285,3.5357802,0
2,17.713495,-2.6983683,3.3584955,0
3,17.106792,-5.2200847,4.727033,0
4,19.82562,3.1341507,3.834365,0
5,19.019388,1.9219573,5.6495733,0
6,18.546461,1.6253153,6.850214,0
7,17.545639,4.703565,7.0512614,0
我想隔离第二行第一行 17.02241 中的值,并稍后在程序中将其用作浮点数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.