应用实例2(显示1-100中含3的整数):
Sub usage2() Dim dic As Object, i As Long Set dic = CreateObject("Scripting.Dictionary") For i = 1 To 100 dic.Add i, "" Next MsgBox Join(Filter(dic.keys, "3"), vbCrLf) Set dic=Nothing End Sub =================================================================== 上面是狼版的,感觉Join(Filter(dic.keys, "3"), vbCrLf) 感觉非常的奇妙,这里通过把 i 变成Dictionary 主键的方式变成了字符串,然后通过Filter函数进行操作。我尝试用自己的方式,借用函数公式中常用的 LEN(),SUBSTITUTE,来判断某数字是否包含某字符,发觉在代码中似乎 SUBSTITUTE 变成了 REPLACE,并且数字 必须先经过 CSTR 转化。CSTR=CHANGE (TO) STRING.尝试了一下居然是对的,开心... Sub usage22() Dim dic As Object, i As Long Set dic = CreateObject("scripting.dictionary") For i = 1 To 100 If Len(CStr(i)) - Len(Replace(i, 3, "")) <> 0 Then dic.Add i, Nothing End If Next MsgBox Join(dic.Keys, vbCrLf) End Sub |