小编Ehs*_*zir的帖子

C# 中与通配符搜索的字符串比较

我有两个字符串用于比较

String Str1 = "A C";
String Str2 = "A B C";
Str2.Contains(Str1); //It will return False ,Contains append % at Start and End of string 

//Replace space with %
Str1 = "%A%C%"; 
Str2 = "%A%B%C%";
Str2.Contains(Str1); //Want it to return True ,
Run Code Online (Sandbox Code Playgroud)

我们确实有Contains,StartsWith,EndsWith比较的方法,但我的要求是,如果我们比较str2str3,它应该返回True,因为它位于Str2中。

我们可以在 C# 中实现这样的行为吗?我已经在 SQL 中做到了这一点,但在 C# 中没有得到一些有用的东西。任何正则表达式等?

c# regex wildcard

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

regex ×1

wildcard ×1