开发者

Selenium C#: string contains

开发者 https://www.devze.com 2023-03-22 12:06 出处:网络
I have something like: string result = Selenium.GetText(\"/html/body/form/div[2]\"); if (result.Contains(\"test\")

I have something like:

string result = Selenium.GetText("/html/body/form/div[2]");
if (result.Contains("test")
{
   bool found = true;
}
else
{
   found = false;
}

My problem is using result.Contains() returns false if there are tests, testing, etc. Also returns false for uppercase TEST, Test, etc

Is there another method that would match each character? Something like: result.M开发者_运维问答atch("test");

Thanks for helping me out.


string.StartsWith is a good start, and then Regex if you need more power


Pardon my awful code, though it works:

var aStartsWithB = stringA.ToUpper().StartsWith(stringB.ToUpper());
var aContainsB = stringA.ToUpper().Contains(stringB.ToUpper());


contains it should work fine:

public static void Main()
{
    string result = @"/html/body/form/tests123456";
    var containsTest= result.Contains("test"); // <--True
}

Just bear in mind that Contains is case sensitive

You could use a version of string.Contains case insensitive as showed on the post below.

0

精彩评论

暂无评论...
验证码 换一张
取 消