2017-02-02 200 views
0

應用程序.net C# 我有問題如何退出(按鈕單擊)從lista.txt文件中的這個(四捨五入的紅色)值。事實上,這是一個匯率表。價值觀每天都在變化。礦山總是在同一個位置。 enter image description here從多行/列字符串獲取字符串的一部分

到目前爲止,使用line.substring我已經得到了整個列內聯: 5,2599355,3058300,2770031,0057322,4095196,1123050,8419020,7941597,0027418,7470806,926223 7,479628 1,729514

我該如何得到一個大膽的部分。它的近尾(7,479628)。 非常感謝。

+0

請添加到目前爲止寫入的代碼,以達到所需的行 – Steve

回答

1

String.Split()應該可以做你想做的。

如果你已經擁有的列這將是:

var array = column.Split('\t'); //assuming the separator is a tab 
0

在它看起來像線圖像的選項卡分隔? 你可以閱讀每一行,然後使用製表符進行分割....

string[] arsplit = line.Split('\t'); 

,然後抓住從在此基礎上我相信指數數組的項目,你就會知道

0

試着這麼做這

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     const string FILENAME = @"lista.txt"; 
     static void Main(string[] args) 
     { 
      StreamReader reader = new StreamReader(FILENAME); 
      int lineCount = 0; 
      string inputline = ""; 
      do while((inputline = reader.ReadLine()) != null) 
      { 
       if(++lineCount == 13) 
       { 
        string[] inputArray = inputline.Trim().Split(new char[] {' ','\t'},StringSplitOptions.RemoveEmptyEntries); 

        Console.WriteLine("Exchange Rate : '{0}'", inputArray[2]); 
        break; 
       } 
      } 

     } 
    } 

} 
0

我剛剛收到的解決方案,從一個人工作正常。他的建議是檢查我感興趣的歐元。所以,下載文件後,方法是:

 int counter = 0; 
     string line; 

     System.IO.StreamReader file = new System.IO.StreamReader(fullPath); 
     while ((line = file.ReadLine()) != null) 
     { 
      if (counter == 0)//jump first row, it's header don't need it 
      { 
       counter++; 
       continue; 
      } 
      if (line.Contains("EUR")) 
      { 
       line = line.Replace(" ", "");//clean spaces 
       line = line.Substring(3 + 3 + 3 + 8, 8); 
      Response.Write(line); 
      } 

      counter++; 

     } 

     file.Close(); 

所以它可能對某人有用。在這一刻,我不知道你的哪個解決方案是最好的。只是想感謝大家在這麼短的時間內幫助我。