2016-09-08 9 views
-1

ファイルダイアログを開くアプリケーションを作成しました。ファイルを開いてテキストボックスにその内容を表示することができます。 Howvever、私が本当に必要とするファイルからのテキストの3つのブロックがあります。私はこれらのテキストブロックだけを「解析する」ことができる必要があります。私はreadalllinesを使用しました。しかし、どのループを使ってソートするかはわかりません。任意の助けいただければ幸い:テキストのブロックのテキストボックスのテキストファイルから特定のテキスト行を表示するにはどうすればよいですか?

私のコード

private void button1_Click(object sender, EventArgs e) 
{ 
    Stream myStream; 
    OpenFileDialog openFileDialog1 = new OpenFileDialog(); 

    //Setting initial directory to the automated repository 
    openFileDialog1.InitialDirectory = "\\\\10.2.XXX.XX\\Repository\\AutomatedVersionRepository\\JMN Web Application\\"; 

    // Set filter options and filter index. 
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|Config files (*.config*)|*.config*"; 
    openFileDialog1.FilterIndex = 2; 
    openFileDialog1.Multiselect = true; 
    openFileDialog1.RestoreDirectory = true; 

    // Call the ShowDialog method to show the dialog box. 
    //bool? userClickedOK = openFileDialog1.ShowDialog() ==DialogResult.OK; 
    if (openFileDialog1.ShowDialog() ==System.Windows.Forms.DialogResult.OK) 
    { 
     if ((myStream = openFileDialog1.OpenFile()) !=null) 
     { 
      string strfilename = openFileDialog1.FileName; 
      string []filetext = File.ReadAllLines(strfilename); 
      foreach (string line in File.ReadLines(strfilename)) 
      { 
       //process the line 
      } 
      //richTextBox1.Text = filetext; 
     } 

例:

<!---Interface URLS and settings--> 
<add key="IUFUploadPath" value="" /> 
<add key="JSDskAPIURL" value="http://api.documentation.com/16_4" /> 
<add key="PvAPIURL" value="http://devapi.documentation.com/16_4" /> 
<add key="FirstDataWebServiceURL" value="https://dev.SpectrumRetailNet.Com/PPSAPI" /> 
<add key="ReportServerUrl" value="https://reports64.documentation.com/9_2_0/FrameHost.aspx" /> 
<add key="HelpassAdminUrl" value="http://Helpppass.documentation.com/app/AdminConsole.aspx" /> 
<add key="XAIMAPIURL" value="//devquippe.documentation.com/ws.aspx" /> 
+0

これは、XMLのように見える使用するコードですあなたは仕事をはるかに簡単にするxmlクラスを使用する必要があります。 – jdweng

答えて

0

これは私が

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

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     const string FILENAME = @"c:\temp\test.xml"; 
     static void Main(string[] args) 
     { 
      Dictionary<string, string> settingsDict = new Dictionary<string, string>(); 
      XmlReaderSettings settings = new XmlReaderSettings(); 
      settings.ConformanceLevel = ConformanceLevel.Fragment; 
      XmlReader reader = XmlReader.Create(FILENAME, settings); 
      while (!reader.EOF) 
      { 
       if (reader.Name != "add") 
       { 
        reader.ReadToFollowing("add"); 
       } 
       if (!reader.EOF) 
       { 
        XElement add = (XElement)XElement.ReadFrom(reader); 
        settingsDict.Add((string)add.Attribute("key"), (string)add.Attribute("value")); 
       } 
      } 
     } 
    } 
} 
+0

ありがとうJdweng私はあなたの提案をお試しになります! – Sonic1980

関連する問題