2017-10-11 16 views
1

テキストファイルのリストから検索語が必要です。各単語はスペースまたはセミコロンで区切られています。データテーブルに行を追加し、それらをデータグリッドに表示します。問題は最後の単語だけが表に表示されていることです。前もって感謝します。テキストボックス内の各単語をテキストファイルから検索し、データテーブルに追加

Sub test(ByVal strtofind As String) 
    Dim tmp2Table As DataTable = New DataTable 

    tmp2Table.Columns.Add("SN", GetType(String)) 
    tmp2Table.Columns.Add("Dataset", GetType(String)) 
    tmp2Table.Columns.Add("Param", GetType(String)) 
    tmp2Table.Columns.Add("Value", GetType(String)) 

    Dim strTemp() As String 
    Dim lines() As String 
    Dim strline As String = "" 

    Dim fileList = Directory.GetFiles("C:\Users\sterc\Desktop\Traceview\Complete\", "*.txt", False) 
    Dim sb = New StringBuilder() 
    Dim result As String = String.Empty 
    Dim value As String = String.Empty 
    Dim s As String = txtParamSearch.Text 
    Dim str As String = "" 
    Dim strdataset As String = "" 
    Dim strParam As String = "" 
    Dim strParamResult As String = "" 
    Dim strSN As String = "" 

    For Each fileName In fileList 
     lines = File.ReadAllLines(fileName) 
     Dim intTotalLines As Integer = lines.Length 
     ' Split string based on spaces. 
     For intCounter = 1 To intTotalLines - 1 
      strline = lines(intCounter) 
      If (Regex.IsMatch(strline, "----- Test_") And Regex.IsMatch(strline, ", Started At ")) Then 

       strTemp = strline.Split(" ") 
       strdataset = strTemp(3).TrimEnd(",") 
      End If 
      If Regex.IsMatch(strline, "Reported module serial number:") Then 
       strTemp = Regex.Split(strline, ": ") 
       strSN = strTemp(1) 
      End If 
      Dim strParamtofind As String = "\b" & strtofind & "\b\s+(\w+)" 

      For Each a As Match In Regex.Matches(strline, strParamtofind, RegexOptions.IgnoreCase) 

       tmp2Table.Rows.Add(strSN, strdataset, a.Groups(0).Value, a.Groups(1).Value) 

      Next 

     Next 

    Next 
    DataGridView1.DataSource = tmp2Table 

End Sub 

Sub strArr() 

    Dim s As String = txtParamSearch.Text 
    Dim str As String = "" 

    Dim words As String() = s.Split(New [Char]() {";"c}) 

    Dim word As String 
    For Each word In words 
     test(word) 
    Next 

End Sub 

enter image description here

もう一つは、全体の数やラウンドオフを表示しています。下図のように仮定します。私は、テキストファイルからのデータ/秒を検索する必要が

enter image description here


(小数点付き)、各ファイルには、線の下に入っています。それから私は見つけるために私がテキストボックスにリストされるかもしれないデータです。 テキストボックスから検索する必要があります。

  • SOA_MinCurrent_EDATA;
  • Isoa_OPSL_initial

記載されている2のそれぞれは、フォルダの下にリストされた各テキストファイルを検索します。次に、それらを1行ずつ表示します。上記のスクリーンショットのように。問題は、文字列検索だけが表示され、数字は丸められます。


Testing tune_rf_pwr-rm-f-tpt ----- Test_TxLaserPwrTune, Started At 9/16/2017 5:25:00 PM 
more lines here.... 
................... 
---tx_laser_pwr_tune_Params Isoa_OPSL,Isoa_OPSH,laser_power_sp 
---laser_power_target 2.5 
---laser_power_initial 2.45000004768372 
---Isoa_OPSL_initial 2.67 
---Isoa_OPSH_initial 2.67 
---laser_power_sp_initial 2.67 
---Isoa_OPSL 2.67 
---Isoa_OPSH 2.67 
---laser_power_sp 2.67 
---laser_pwr_tune 2.45000004768372 
---laser_power_target056 2.46 
---SOA_MinCurrent_EDATA 23.7778471526403 
---SOA_MinCurrent_Chan 22 
---SOA_MaxCurrent_EDATA 45.1157734448841 
---SOA_MaxCurrent_Chan 98 
---SOA_Current_initial[056] 57.082 
---SOA_Current_initial[022] 49.389 
---SOA_Current_initial[098] 49.389 
---laser_power 2.46 
---SOA_Current056 57.082 
---SOA_Current022 49.389 
---SOA_Current098 68.437 
---tune_rf_sp_data:tx_laser_pwr_tune_Params Isoa_OPSL,Isoa_OPSH,laser_power_sp 
---tune_rf_sp_data:laser_power_target 2.5 
---tune_rf_sp_data:laser_power_initial 2.45000004768372 
---tune_rf_sp_data:Isoa_OPSL_initial 2.67 
---tune_rf_sp_data:Isoa_OPSH_initial 2.67 
---tune_rf_sp_data:laser_power_sp_initial 2.67 
---tune_rf_sp_data:Isoa_OPSL 2.67 
---tune_rf_sp_data:Isoa_OPSH 2.67 
---tune_rf_sp_data:laser_power_sp 2.67 
---tune_rf_sp_data:laser_pwr_tune 2.45000004768372 
---tune_rf_sp_data:laser_power_target056 2.46 
---tune_rf_sp_data:SOA_MinCurrent_EDATA 23.7778471526403 
---tune_rf_sp_data:SOA_MinCurrent_Chan 22 
---tune_rf_sp_data:SOA_MaxCurrent_EDATA 45.1157734448841 
---tune_rf_sp_data:SOA_MaxCurrent_Chan 98 
---tune_rf_sp_data:SOA_Current_initial[056] 57.082 
---tune_rf_sp_data:SOA_Current_initial[022] 49.389 
---tune_rf_sp_data:SOA_Current_initial[098] 49.389 
---tune_rf_sp_data:laser_power 2.46 
---tune_rf_sp_data:SOA_Current056 57.082 
---tune_rf_sp_data:SOA_Current022 49.389 
---tune_rf_sp_data:SOA_Current098 68.437 
+0

単語の文字列データ型を使用する代わりに、(文字列の)リストを使用して、各セミコロン分割を処理するループを使用してそれらをリストに追加し、データのリストをループすることがありますテーブルの行 – AustinS90

答えて

0

あなたは私はあなたを助けることができるより多くの情報を提供する場合、私はここで少し混乱しています。

複数のファイルがあり、各列の値がスペースで区切られ、ファイル内にセミコロンがなく、各列の値がセミコロンで区切られ、ファイル内に空白がないファイル?前の質問がtrueで、ファイル内の各行は、各行を記入します情報が含まれている場合

、その後、私が使用します。

Dim r as StreamReader as New StreamReader(FilePath) 
Dim Line as String 

Do While StreamReader.Peek() > -1 //Go through the file until EOF 

Line = r.readline() //Read the line and put it into Line 
If InStr(Line, " ") Then //Search for spaces inside Line 
//This file is separated by spaces, put the code to add to the table. 
Else If InStr(Line, ";") Then //search for semicolons inside line. 
//This file is separated by semicolons, put the code to add to the table. 
End If 

Loop 

私はこのことができます願っています。そうでない場合は、もう少し詳細を教えてください。

+0

こんにちはAlvaro、私は詳細を追加しました。 – Badz

+0

こんにちはAlvaro、私はbutton_clickにdatatableを置くことで問題を解決しました。今すぐ完璧に動作します。御時間ありがとうございます。 – Badz

関連する問題