简体   繁体   English

从字符串B中删除字符串A中的字符串

[英]Remove strings from string A that are in array B

I have array A and Array B , I want to get as result A\\B (to get only the strings that in A but not in B). 我有数组A和数组B,我想作为结果A \\ B(仅获取A中而不是B中的字符串)。

Of course I can do two for loops and do it , but is there some more nice way to do so ? 当然,我可以做两个for循环来做,但是还有其他更好的方法吗?

Thanks for help , i use .net3.5 感谢您的帮助,我使用.net3.5

You can use LINQ: 您可以使用LINQ:

var difference = A.Except(B);

This uses a HashSet and will be substantially faster than nested for loops for large sets. 这将使用HashSet,并且比大型集的循环嵌套for快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM