使用关键字对数组进行模糊查找;对一维字符串数组进行排序
一、对一个一维数组进行关键字查询,将结果放到数组中。(这个查找是区分大小写的。)
Public Function GetSubArrayByKey(ByVal v_arrSheetName As String(), ByVal v_strFilter As String) As String() Try Dim arrReturn As String() arrReturn = Array.FindAll(v_arrSheetName, Function(s) (s.IndexOf(v_strFilter) >= 0))
For Each Str As String In arrReturn Console.WriteLine(Str) Next Return arrReturn Catch ex As Exception Throw Return Nothing End Try End Function
二、对数组进行排序
''' <summary> ''' 对一维字符串数组进行排序 ''' </summary> ''' <param name="v_arrStr">要排序的字符串</param> ''' <param name="v_IsASCMode">True为正序,Flase为倒序。默认为True</param> ''' <returns>排序之后的一维字符串数组</returns> ''' <remarks></remarks> Public Function SortStringArray(ByVal v_arrStr As String(), Optional ByVal v_IsASCMode As Boolean = True) As Array If (v_arrStr.Count > 0) Then If v_IsASCMode Then Array.Sort(v_arrStr) Else Array.Reverse(v_arrStr) End If End If Return v_arrStr End Function