在C#中的网址分裂? [英] URL split in C#?
本文介绍了在C#中的网址分裂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像 example.com/page?a=1&ret=/user/page2
的URL。
I have a url like example.com/page?a=1&ret=/user/page2
.
我使用string.split('/')找出路径,但这种情况下,你可以看到它是不是非常有用。我如何拆分URL,所以我可以在页面的路径?
I was using string.split('/') to figure out the paths but this case you can see it isn't very useful. How do i split the URL so i can get the page path?
推荐答案
如果您从您的字符串的System.Uri对象,它将对路径的不同部分的几个属性:
If you make a System.Uri object from your string, it will have several properties for different parts of the path:
string path = "http://example.com/page?a=1&ret=/user/page2";
Uri uri = new Uri(path);
Console.WriteLine(uri.AbsolutePath); // Prints "/page"
这篇关于在C#中的网址分裂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文