我需要從文本文件列表中搜索單詞,並且每個單詞在文本框中用空格或分號分隔。將行添加到數據表並將其顯示到數據網格。問題只是表格中顯示的最後一個字。提前致謝。從文本文件中搜索文本框中的每個單詞並添加到數據表
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
另一件事是顯示整個號碼或四捨五入。假設像下圖。(帶小數點)
我需要從一個文本文件中搜索數據/秒,每個文件都包含以下行。然後在它下面是我可能列在文本框中查找的數據。 讓我們來看看我需要找到的文本框,
- SOA_MinCurrent_EDATA;
- Isoa_OPSL_initial
每個列出的兩個的,將搜索一個文件夾下的每個文本文件。然後逐行顯示它們。就像上面的截圖一樣。問題是隻顯示字符串搜索和數字四捨五入。
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
也許,不是爲單詞使用字符串數據類型,而是嘗試使用一個(字符串)列表,並使用循環來處理每個分號分割,將它們添加到列表中,並循環遍歷數據列表表格行 – AustinS90