重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
有啊,用正则表达式,下面是简单的例子
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、雅安服务器托管、营销软件、网站建设、威宁网站维护、网站推广。
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = "ABCDAEAFAG"
Dim Patter As String = "A"
Dim Matches As MatchCollection = Regex.Matches(str, Patter, RegexOptions.IgnoreCase Or RegexOptions.ExplicitCapture)
For Each ws In Matches
ListBox1.Items.Add("索引位置:" ws.index)
Next
End Sub
End Class
步骤如下:
窗体上添加2个列表框,一个按钮:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
'搜索并显示子文件夹
ListBox1.Items.Clear()
For Each MySubDir As String In System.IO.Directory.GetDirectories(MyDir)
ListBox1.Items.Add(MySubDir)
Next
'搜索并显示文件
ListBox2.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir)
ListBox2.Items.Add(MyFile)
Next
End Sub
End Class
解压密码:1299
假设路径为C:\abc
代码:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Files As ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles("C:\abc")
Dim FileSize As Long, FileName As String = Nothing
Dim oFileSize As Long
For Each File As String In Files
oFileSize = My.Computer.FileSystem.GetFileInfo(File).Length
If oFileSize FileSize Then
FileSize = oFileSize
FileName = File
End If
Next
Dim ListN As ListViewItem = New ListViewItem(My.Computer.FileSystem.GetName(FileName))
ListN.SubItems.Add(oFileSize " byte")
ListN.SubItems.Add(My.Computer.FileSystem.GetFileInfo(FileName).Extension " 文件")
ListN.SubItems.Add(FileName)
ListView1.Items.Add(ListN)
End Sub
End Class
详见源代码!!
思路:
1,使用ListBox1控件来存放搜索到的文件名,然后ListBox1.SelectedItem就可以返回选中项的文本;
2,利用获得的选中项文本(即文件与路径),使用打开文本文件的方法,读取内容显示在文本框里。
窗体上添加一个文本框,一个列表框,一个按钮:
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
Dim MyFilter As String = "*" TextBox1.Text "*"
ListBox1.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir, MyFilter)
ListBox1.Items.Add(MyFile)
Next
End Sub