May*_*aya 8 c# string-comparison ignore-case
string body = Selenium.GetBodyText();
if (body.Contains("software", StringComparison.CurrentCultureIgnoreCase))
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
string does not contain a definition for Contains当我做上述事情时,我收到了一条消息.我在这做错了什么?在此先感谢大家!
我试图检查身体是否有字符串"软件","软件"或"软件".body将包含文本的段落和段落(字符串).
Jon*_*eet 10
我不相信string有过载Contains走StringComparison.但是,你可以使用IndexOf 哪个:
if (body.IndexOf("software", StringComparison.CurrentCultureIgnoreCase) != -1)
Run Code Online (Sandbox Code Playgroud)
小智 7
我不确定您是否使用.NET 1.1,但它不包含该方法Contains.你必须使用IndexOf..NET 2.0添加了方法Contains(每个MSDN).使用IndexOf,您可以使用StringComparison.
您可以使用正则表达式匹配C#中的字符串搜索.您还可以选择忽略大小写.
if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
Run Code Online (Sandbox Code Playgroud)
此链接可能很有用:如何:使用正则表达式搜索字符串(C#编程指南)
| 归档时间: |
|
| 查看次数: |
5960 次 |
| 最近记录: |