【发布时间】:2019-03-07 14:30:05
【问题描述】:
我无法弄清楚 EndsWith 为何返回 false。
我有 C# 代码:
string heading = "yakobusho";
bool test = (heading == "yakobusho");
bool back = heading.EndsWith("sho");
bool front = heading.StartsWith("yak");
bool other = "yakobusho".EndsWith("sho");
Debug.WriteLine("heading = " + heading);
Debug.WriteLine("test = " + test.ToString());
Debug.WriteLine("back = " + back.ToString());
Debug.WriteLine("front = " + front.ToString());
Debug.WriteLine("other = " + other.ToString());
输出是:
heading = yakobusho
test = True
back = False
front = True
other = True
EndsWith 是怎么回事?
【问题讨论】:
-
将其复制到dotnetfiddle 突出显示
"sho"开头有一个隐藏字符 -
不同的字符,可能是隐藏字符。
EndsWith()没有错 -
第三行的
"sho"字符串长度为4个字符