检查字典是否包含子字符串? [英] Check if dictionary contains substring?
本文介绍了检查字典是否包含子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有两个带有以下键值对的字典:
Say I have two dictionaries with the following key value pairs:
1, "Hello"
2, "Example"
另一本字典如下:
1, "HelloWorld"
2, "Example2"
我想确定这些词典中是否包含子字符串"hello".
dictionary.ContainsValue("Hello")
将适用于第一个示例,但不适用于第二个示例.如何检查字典中所有值中是否存在子字符串?
I want to find out if these dictionaries contain the substring "hello" within them. dictionary.ContainsValue("Hello")
will work for the first example but not the second one. How can I check for existence of a substring in all values in a dictionary?
推荐答案
只需使用Any
来检查包含"Hello"的第一个值
Just use Any
to to check for the first Value that contains "Hello"
dictionary.Any(kvp=>kvp.Value.Contains("Hello"))
这篇关于检查字典是否包含子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文