有什么可以替换 AbsolutePath.Contains 的吗?
我有一个 Uri,其中包含我放入 if 块中的路径的一部分。 它就像
if (absUri.AbsolutePath.Contains("W3C//DTD%20XHTML%201.1//EN"))
我想用更可靠和更健壮的东西替换 .Contains 部分,就好像 //EN 之后有一些字符串,即使这样也能满足 if 块。 整个路径是这样的:C:/Users/a/desktop/fol/W3C//DTD%20XHTML%201.1//EN。 有什么方法吗?
I have a Uri that contains a part of the path that i am putting in the if block. Its something like
if (absUri.AbsolutePath.Contains("W3C//DTD%20XHTML%201.1//EN"))
I want to replace .Contains part with something more reliable and robust as if there is some piece of string after //EN, even that will satisfy the if block. The whole path is something like this: C:/Users/a/desktop/fol/W3C//DTD%20XHTML%201.1//EN.
Is there any method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜我正在寻找类似 .EndsWith 的东西。
I was looking for something like .EndsWith i guess.
好吧,如果“//EN”后面有什么内容也没关系,因为该字符串仍然包含您的搜索词。
您提到您想要更可靠的东西& 强大,那么你看到了什么问题?
正如您所意识到的,如果“//EN”后面有任何内容或者发生变化,
.EndsWith
将会失败,但我认为它并不比.Contains
更可靠。代码>. 事实上,我希望他们彼此一样可靠。Well it shouldn't matter if there's something after the "//EN" as the string will still contain your search term.
You mention you want something more reliable & robust so what problem are you seeing?
As you've realised
.EndsWith
will fail if there is anything after the "//EN" or if that varies, but I don't think it's any more reliable than.Contains
. In fact I'd expect them to be as reliable as each other.