获取字符串/数组包含的值的计数

时间:2015-04-09 02:03:29

标签: arrays vb.net count

我最初有这样的字符串:(我使用MySQL的GROUP_CONCAT()函数)

oldArrStr = "1, 2, 79, 5, 6, 7"
newArrStr = "4, 6, 2, 13, 7, 9"

我碰巧需要将newArrStr与oldArrStr进行比较,它应该返回匹配值的计数。在这种情况下:oldArrStr和newArrStr都有:2,6,7,所以它应该返回3

提前感谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

Dim oldArrStr = "1, 2, 79, 5, 6, 7"
Dim newArrStr = "4, 6, 2, 13, 7, 9"

Dim count = _
    oldArrStr.Split(","c).Select(Function (x) x.Trim()) _
        .Intersect(newArrStr.Split(","c).Select(Function (x) x.Trim())) _
        .Count()

根据你的问题,我得到三个。

你可以摆弄它here