可以使用Linq来查找值是否与较大字符串的一部分匹配?

use*_*186 4 c# regex linq

我已经用linq查看了RegEx和SQLMatch,但我似乎无法找到适合我情况的规则.我想创造的将是......

//dataCollected[0] = { Name="joe", Url="http://my.home.site/" }
//dataCollected[N] = { Name="example", Url="http://german.home.site/" }

public bool hasParent(string test_url){
    var obj = dataCollected.Where(s => ( test_url.contains(s.Url)));
    return obj.Count() > 0;
}

bool  result  = hasParent("http://my.home.site/ShouldBeTrue"); //Finds http://my.home.site/
Run Code Online (Sandbox Code Playgroud)

gle*_*eng 6

你几乎就在那里,应该是另一种方式.另外,使用LINQ Any.如果找到任何匹配项,则返回true:

public bool hasParent(string test_url)
{
    return dataCollected.Any(s => test_url.Contains(s.url));
}
Run Code Online (Sandbox Code Playgroud)