在 C# 中比较两个相同的字符串但返回 false。不知道为什么????
Comparing two same string but returning false in C#. Don't know why????
public bool VerifyTextPresent(By by, String actual)
{
WaitUntilElementIsPresent(by);
String expected = GetText(by);
return expected.Equals(actual);
}
预期="Total Win"
实际 = "Total Win"
我也使用了 "Contains" 方法,但仅 return false。
请帮我解决这个问题。
I got the thing like i ptrinted its ascii value and for actual space value is 160 and for expected space value is 32. But now how can i now move ahead??
一种方法是通过用基线替换某些字符来规范化字符串。在您的情况下,您可以用 "normal" space:
替换不间断的 spaces
public bool VerifyTextPresent(By by, String actual)
{
WaitUntilElementIsPresent(by);
String expected = GetText(by);
if (expected.Equals(actual)) return true;
if (expected.Equals(Normalize(actual))) return true;
return false;
}
private string Normalize(string s)
{
// hard-code for now; could use a lookup table or other means to expand
s = s.Replace((char)160, (char)32);
// other replacements as necessary
return s;
}
public bool VerifyTextPresent(By by, String actual)
{
WaitUntilElementIsPresent(by);
String expected = GetText(by);
return expected.Equals(actual);
}
预期="Total Win"
实际 = "Total Win"
我也使用了 "Contains" 方法,但仅 return false。 请帮我解决这个问题。
I got the thing like i ptrinted its ascii value and for actual space value is 160 and for expected space value is 32. But now how can i now move ahead??
一种方法是通过用基线替换某些字符来规范化字符串。在您的情况下,您可以用 "normal" space:
替换不间断的 spaces public bool VerifyTextPresent(By by, String actual)
{
WaitUntilElementIsPresent(by);
String expected = GetText(by);
if (expected.Equals(actual)) return true;
if (expected.Equals(Normalize(actual))) return true;
return false;
}
private string Normalize(string s)
{
// hard-code for now; could use a lookup table or other means to expand
s = s.Replace((char)160, (char)32);
// other replacements as necessary
return s;
}