Hello Please some help me with a code or algorithm to do this effectively.
I have two arrays ArrayA and ArrayB. I would love to search for A in B to return the result below
ARRAY A:
{“JACK|MATTER|15|Montgomery|40037228”
,“RICHARD|MATTER|35|ROWTOWN|40037228”
,“BECK|SPENCER|25|HuggesTown|40037228”
,“DAVID|MARY|28|HELLSPOT|5637829222”}
ARRAY B:
{“MATTER|JACK|Montgomery”,
“RICHARD|BOXER|ROWTOWN”,
“DAVID|MARY|HELLSPOT”}
RESULT:
{“DAVID|MARY|28|HELLSPOT|5637829222”,
“JACK|MATTER|15|Montgomery|40037228”}
Yoichi
(Yoichi)
July 17, 2022, 1:29pm
2
Hi,
How about the following?
arrResult = arrA.Where(Function(s1) arrB.Any(Function(s2) s2.Split("|"c).All(Function(ss) s1.Split("|"c).Contains(ss)))).ToArray()
Sequence4.xaml (6.3 KB)
Regards,
1 Like
Hey @MasterOfLogic
Try the linq Intersect
which should help.
Thanks
#nK
2 Likes
Hello Thanks @Yoichi for always coming to the rescue. It works fine , but wanted to add if I had this JACK|MATTER|15|Montgomery Site|40037228 as an element in arrA ,how do I make it still select this?
its not exactly Montgomery but then it has something like it
I modified it to this is this okay ?
arrA.Where(Function(s1) arrB.Any(Function(s2) s2.Split("|"c).All(Function(ss) s1.Contains(ss)))).ToArray()
Yoichi
(Yoichi)
July 17, 2022, 2:27pm
5
Hi,
It should be as the following, for example.
arrA.Where(Function(s1) arrB.Any(Function(s2) s2.Split("|"c).All(Function(ss2) s1.Split("|"c).Any(Function(ss1) ss1.Contains(ss2))))).ToArray()
Evaluate them using Srting.Contains method.
OR
arrA.Where(Function(s1) arrB.Any(Function(s2) s2.Split("|"c).All(Function(ss2) s1.Split("|"c).Any(Function(ss1) ss1.StartsWith(ss2))))).ToArray()
Evaluate them using Srting.StartsWith method.
Please note that there is possibility to match unintended string.
Regards,
system
(system)
Closed
July 20, 2022, 2:27pm
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.