无法获取 .Contains 在 C# 中工作
Can not get .Contains to work in c#
我已经搜索并尝试了数小时的各种事情,但无法使这个简单的包含功能正常工作。
if (department.ToLower().Contains(item2.Title.ToLower()))
这是两个字符串的图像。我已经将它们复制到记事本中进行比较,它们是相同的。
感谢您的任何建议。
这是文本中的两个字符串,直接从 visual studio 调试器复制:
String 1 : "Shared Services - Technology and Information Services"
String 2 : "Shared Services - Technology and Information Services"
编辑 - 在文本中添加字符串
代码应该有效(基于 csharp
交互式 shell):
$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> var dep="Shared Services - Technology and Information Services";
csharp> var oth="Shared Services - Technology and Information Services";
csharp> dep.ToLower().Contains(oth.ToLower())
true
您确定执行了带有 if
语句的代码吗,也许您应该将值复制到这里,因为可能会有一些小差异(例如 space)。
根据图像,department
字符串中的破折号 (-
) 后似乎有两个 space。但这可能是字体的一个技巧。但总的来说,使用图像而不是提供原始文本数据(可以复制和处理)是非常糟糕。
看起来它只是一个 visual studio 编译器错误。我刚刚重新启动了我的电脑,现在它似乎工作正常。
我已经搜索并尝试了数小时的各种事情,但无法使这个简单的包含功能正常工作。
if (department.ToLower().Contains(item2.Title.ToLower()))
这是两个字符串的图像。我已经将它们复制到记事本中进行比较,它们是相同的。
感谢您的任何建议。
这是文本中的两个字符串,直接从 visual studio 调试器复制:
String 1 : "Shared Services - Technology and Information Services"
String 2 : "Shared Services - Technology and Information Services"
编辑 - 在文本中添加字符串
代码应该有效(基于 csharp
交互式 shell):
$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> var dep="Shared Services - Technology and Information Services";
csharp> var oth="Shared Services - Technology and Information Services";
csharp> dep.ToLower().Contains(oth.ToLower())
true
您确定执行了带有 if
语句的代码吗,也许您应该将值复制到这里,因为可能会有一些小差异(例如 space)。
根据图像,department
字符串中的破折号 (-
) 后似乎有两个 space。但这可能是字体的一个技巧。但总的来说,使用图像而不是提供原始文本数据(可以复制和处理)是非常糟糕。
看起来它只是一个 visual studio 编译器错误。我刚刚重新启动了我的电脑,现在它似乎工作正常。