获取字符串中包含的实例列表中的计数 [英] Get Count in List of instances contained in a string

查看:69
本文介绍了获取字符串中包含的实例列表中的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,最多包含9个 unique 数字,范围从1到9(myString),例如"12345"

I have a string containing up to 9 unique numbers from 1 to 9 (myString) e.g. "12345"

我有一个字符串列表{{1},{" 4}(myList)等.

I have a list of strings {"1"}, {"4"} (myList) .. and so on.

我想知道字符串(myString)中的列表(myList)中包含多少个实例,在上面的示例中,它将返回2.

I would like to know how many instances in the string (myString) are contained within the list (myList), in the above example this would return 2.

类似

count = myList.Count(myList.Contains(myString));

如果需要,我可以将myString更改为列表.

I could change myString to a list if required.

非常感谢

推荐答案

我会尝试以下操作:

count = mylist.Count(s => myString.Contains(s));

这篇关于获取字符串中包含的实例列表中的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆