VBA利⽤字典去重Sub利⽤字典去重()
针刺放血Dim aOld, aNew, Dic '声明数组、字典
Dim i As Long
有一种感觉
Dim sOld, sNew As String'声明字符串
Set Dic = CreateObject("scripting.dictionary")'创建字典
sOld ="a b c 1 2 1 a c d"'旧字符
aOld = Split(sOld," ")'将字符串分割后装⼊数组
For i =LBound(aOld)To UBound(aOld)'遍历数组中的元素
Dic(aOld(i))= vbNullString '利⽤字典key的不重复性去重
Next i
如何学习画画aNew = Dic.keys '将字典的key装⼊数组
公园一角作文
低烧可以洗澡吗sNew = Join(aNew," ")'将数组连接成字符串
Debug.Print "sOld:" & sOld
Debug.Print "sNew:" & sNew
End Sub
返回结果:
三星电池爆炸sOld:a b c 1 2 1 a c d旅游方案
潼关吏sNew:a b c 1 2 d