[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
路过,花时间写了个来支持。
  1. Dim s '源字符串
  2. Dim final '最终字符串
  3. Dim ss,i,j
  4. s="bat home home Net home net Bat net"
  5. 'For i=0 To 10
  6. ' s=s & " " & s
  7. 'Next
  8. ss=Split(s," ")
  9. MsgBox "Length: " & Len(s) & vbNewLine & "Count: " & UBound(ss)+1
  10. ReDim mark(UBound(ss))
  11. For i=0 To UBound(ss)-1
  12. If (mark(i)=0) Then
  13. For j=i+1 To UBound(ss)
  14. If (mark(j)=0) Then
  15. If (StrComp(ss(i),ss(j),vbTextCompare)=0) Then
  16. mark(i)=1:mark(j)=-1
  17. End If
  18. End If
  19. Next
  20. End if
  21. Next
  22. For i=0 To UBound(ss)
  23. If (mark(i)=1) Then final=final & ss(i) & " "
  24. Next
  25. If (Len(final)>0) Then final=Left(final,Len(final)-1)
  26. Erase mark
  27. MsgBox final
复制代码

TOP

再贴一个利用Dictionary对象Key唯一性的方法。
这个和楼上的代码,大部分时间都花在Split上了;不过目前也没有好的解决办法。
  1. Sub Cut2
  2. Dim s '源字符串
  3. Dim final '最终字符串
  4. Dim ss,i
  5. Dim dic '字典对象
  6. Set dic=CreateObject("Scripting.Dictionary")
  7. s="bat home home Net home net Bat net"
  8. ' For i=0 To 10
  9. ' s=s & " " & s
  10. ' Next
  11. ss=Split(s," ")
  12. MsgBox "Length: " & Len(s) & vbNewLine & "Count: " & UBound(ss)+1
  13. For i=0 To UBound(ss)
  14. If (dic.Exists(LCase(ss(i)))=False) Then dic.Add LCase(ss(i)),ss(i)
  15. Next
  16. Erase ss
  17. For Each item In dic.Items
  18. final=final & item & " "
  19. Next
  20. Set dic=Nothing
  21. If (Len(final)>0) Then final=Left(final,Len(final)-1)
  22. MsgBox final
  23. End Sub
复制代码
1

评分人数

TOP

返回列表