以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [字符串数组差集] (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=68141) |
-- 作者:lifeofyiyi -- 发布时间:2015/5/11 10:20:00 -- [字符串数组差集] 请教我想得出两个字符串数组的差集该怎么做呢 Dim sd() as string = {“8:00”,“8:15”,“8:30”,“8:45”} Dim sd1() as string = {“8:00”,“8:15”} 我想得到的结果是 8:30跟8:45
|
-- 作者:Bin -- 发布时间:2015/5/11 10:25:00 -- Dim sd() As String = {"8:00","8:15","8:30","8:45"} Dim sd1() As String = {"8:00","8:15"} Dim sd1s As new List(of String) sd1s.AddRange(sd1) Dim cls As new List(of String) For Each s As String In sd If sd1s.Contains(s)=False Then cls.Add(s) End If Next For Each s As String In cls output.show(s) Next |
-- 作者:lifeofyiyi -- 发布时间:2015/5/11 10:33:00 -- 感谢bin老师,试过用集合的RemoveAt来删除相同的元素,可是没想到用Contains方法比较不同的元素填到另一个集合里,谢谢谢谢! |