这个路径B:\VB测试\333 搜索这3个字段的内容"Hight=""","Width=""","Thickness=""" 显示在DataGridView1中 显示格式要"Hight="""*"Width="""*"Thickness=""" 用VB.NET做
时间: 2023-12-21 13:05:33 浏览: 119
Hight-Speed Charting)
首先,我们需要使用VB.NET的FileSystemObject类来遍历指定路径下的所有文件。然后,我们可以使用正则表达式来匹配和提取所需的字段内容。最后,将这些内容添加到DataGridView1中。
以下是实现这个功能的VB.NET代码:
```vb
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim folderPath As String = "B:\VB测试\333"
Dim files As String() = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories)
Dim dataGridView1 As New DataGridView()
dataGridView1.ColumnCount = 3
dataGridView1.RowCount = 0
For Each file As String In files
Dim content As String = File.ReadAllText(file)
Dim matches As MatchCollection = Regex.Matches(content, "Hight=""(.*?)""")
Dim hight As String = If(matches.Count > 0, matches(0).Groups(1).Value, "")
matches = Regex.Matches(content, "Width=""(.*?)""")
Dim width As String = If(matches.Count > 0, matches(0).Groups(1).Value, "")
matches = Regex.Matches(content, "Thickness="""(.*?)""")
Dim thickness As String = If(matches.Count > 0, matches(0).Groups(1).Value, "")
dataGridView1.Rows.Add({hight, width, thickness})
Next
Me.Controls.Add(dataGridView1)
End Sub
End Class
```
这段代码首先获取指定路径下的所有文件,然后使用正则表达式匹配和提取Hight、Width和Thickness字段的内容。将提取到的内容添加到DataGridView1中,并设置其列数为3。
阅读全文