为什么 c# string.TrimStart 会修剪参数的尾随空格?
在代码中:
string s = "Executing".TrimStart(@"Exec ".ToCharArray());
或者
string s = "Executing".TrimStart("Exec ".ToCharArray());
s 将等于 "uting",尽管尾随空格字符,而
bool t = "Executing".StartsWith("Exec ");
t 将等于 False?
In code:
string s = "Executing".TrimStart(@"Exec ".ToCharArray());
or
string s = "Executing".TrimStart("Exec ".ToCharArray());
s will equal "uting" in spite of the trailing space character while
bool t = "Executing".StartsWith("Exec ");
t will equal False?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TrimStart
的char[]
参数表示一组字符,而不是字符串。换句话说,它将删除char[]
数组中字符串开头的所有连续字符 - 它不会检查字符是否与序列匹配数组中的字符数。 (如果它确实这样做了,那么接受string
不是更有意义吗?)The
char[]
argument toTrimStart
implies a set of characters, not a string. In other words it will remove all the consecutive characters from the start of the string that are in thechar[]
array -- it will not check that the characters match the sequence of characters in the array. (If it did do that, wouldn't it make more sense for it to accept astring
?)