[VB6][VB.NET] 依 关键字 搜寻 数组 值 / 字符串

摘要:[VB6][VB.NET] 依 关键字 搜寻 数组 值 / 字符串


Filter相当好用主要是用来处理数组的值,写程序必备的技巧之一

数据出处:http://msdn.microsoft.com/zh-tw/library/fat7fw0s(VS.80).aspx

VB6:

Option Explicit
Private Sub Command1_Click() Sub Command1_Click()
    Dim myArray()
    Dim myIndex
    Dim v
    List1.Clear
    myArray = Array("Apple", "Boy", "Can", "Dog", "Taipei")
    myIndex = IIf(Option1(0).Value, _
              Filter(myArray, UCase(Text1.Text), True, vbTextCompare), _
              Filter(myArray, UCase(Text1.Text), False, vbTextCompare))
    For Each v In myIndex
        List1.AddItem v
    Next
End Sub

执行画面如下

VB.NET:

Public Class Form1

    Private Sub Button1_Click() Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
        Dim myArray() As String = {"Apple", "Boy", "Can", "Dog", "Taipei"}
        Dim myIndex
        Dim v
        ListBox1.Items.Clear()
        myIndex = IIf(Me.RadioButton1.AutoCheck = True, _
                  Filter(myArray, UCase(TextBox1.Text), True, vbTextCompare), _
                  Filter(myArray, UCase(TextBox1.Text), False, vbTextCompare))
        For Each v In myIndex
            ListBox1.Items.Add(v)
        Next
    End Sub

End Class

执行画面如下

范例下载

过滤字符串.rar

若有谬误,烦请告知,新手发帖请多包涵

2010~2017 C# 第四季