获取 string/array 包含的值的计数

get the count of values that both the string/array contains

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

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

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

提前致谢。

试试这个:

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()

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

你可以fiddle用它here