[問題] 讀取TXT檔的數字
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
問題(Question):
我想要讀取TXT裡的數字,並忽略中文字以及英文。
餵入的資料(Input):
===== Fabrication Task =====
Format Version : 01
== General Information ==
Exposure Time : 1
Laser Power : 0.005000
Voxel Distance : 0.120000
Flag of 'Start from Top' : 1
Flag of 'Multi-Paths' : 0
Number of Multi-Paths : 1
Number of Rules : 0
Flag of 'Shortest Moving Paths' : 1
Flag of 'Smoothing' : 0
Smoothing Distance : 0.500000
== Scan Path Information ==
Number of Total Paths : 53
Path Number : 0
Number of Total Points : 270
1.654347 1.284276 10.000000
1.576632 1.370587 10.000000
1.498918 1.456898 10.000000
1.421203 1.543208 10.000000
預期的正確結果(Expected Output):
01
1
0.005
0.12
.
.
.
依此類推
*[36m錯誤結果(Wrong Output):
我現在只能做到利用空格來擷取每個數子和文字,但我不知道如何忽略文字= =
程式碼(Code):(請善用置底文網頁, 記得排版)
txtFile->Text = openFileDialog1->FileName;
StreamReader^ sr = gcnew StreamReader(txtFile->Text,
System::Text::Encoding::Default);
num = 0;
txtWord->Text = "";
while (sr->Peek() != -1) //判斷是否已經讀取到最後一個字元
{
//讀取一列
String^ currentRow = sr->ReadLine();
try
{
array <String^> ^oneWord = currentRow->Trim()->Split(''); // 單字分解
for each (String^ w in oneWord) // 將分解的單字放入
words[] 陣列中
{
if (!(w->Trim() == "" || w->Trim() == nullptr))
{
txtWord->Text += w + "\r\n";
words[num] = w; // 將分解的單字放入 words[] 陣列中
num += 1; // 共有多少個英文單字
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.68.20
→
05/16 00:24, , 1F
05/16 00:24, 1F
→
05/16 00:27, , 2F
05/16 00:27, 2F
→
05/16 00:27, , 3F
05/16 00:27, 3F
→
05/16 00:36, , 4F
05/16 00:36, 4F
→
05/16 00:39, , 5F
05/16 00:39, 5F
→
05/16 00:47, , 6F
05/16 00:47, 6F
→
05/16 00:54, , 7F
05/16 00:54, 7F
→
05/16 08:57, , 8F
05/16 08:57, 8F
→
05/16 14:34, , 9F
05/16 14:34, 9F