Contains function

Hi everything,
Can anyone help me on this

Str1 = "system.exception unable to find a click sleelector.

Type into click aqaes test knfkajfkaguwbdiwndkdb
Wnajjskdjfjdjdjjwwhn wiwnd exception edjf fmjsnhjwnwh"

Str2 ="System.exception unable to find a click sleelector.

Type into click aqaes test knfkajfkaguwbdiwndkdb
Wnajjskdjfjdjdjjwwhn wiwnd exception edjf fmjsnhjwnwh"

When Iā€™m using if condition like

Str1.trim().contains(str2).trim()

Above 2 string as same letters space everything but still it is falling in false.

Hi @Arya_Squares

You can use this site to compare text

Text Compare! - Find differences between two text files (text-compare.com)

in your case, contains method is case sentitive You can check using this:

Str1.ToLower().Trim().contains(Str1.ToLower().Trim())

it will convert the strings to lowercase before compare

Hi,

There might be difference regarding white space.
Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(str1,"\s+"," ").Contains(System.Text.RegularExpressions.Regex.Replace(str2,"\s+"," "))

Regards,

1 Like

It seems the issue might be with white spaces. Try this expression for a more robust check:
System.Text.RegularExpressions.Regex.Replace(Str1, @ā€œ\s+ā€, " ā€œ).Contains(System.Text.RegularExpressions.Regex.Replace(Str2, @ā€\s+", " "))

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.