[英]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.