有什么可以替换 AbsolutePath.Contains 的吗?

发布于 2024-07-22 03:29:47 字数 277 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青巷忧颜 2024-07-29 03:29:47

我猜我正在寻找类似 .EndsWith 的东西。

I was looking for something like .EndsWith i guess.

和影子一齐双人舞 2024-07-29 03:29:47

好吧,如果“//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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文