[英]Get last path from URL
I have Url in my c# app, for example: https://www.instagram.com/testtesttest/
我的C#应用程序中包含Url,例如: https://www.instagram.com/testtesttest/
: https://www.instagram.com/testtesttest/
And I want to get the last path component from it: testtesttest
我想从中获取最后一个路径组件: testtesttest
I'm using this code: 我正在使用此代码:
public static String GetUserNameInstagramUrl(String url)
{
Uri uri = new Uri(url);
return uri.Segments.Last();;
}
Unfortunately, I'm getting the last path with /
in the end. 不幸的是,我最后得到的是/
。 There is any method to get the last path without removing the /
by myself? 有什么方法可以在不删除/
的情况下获得最后的路径?
Just do TrimEnd at the end 最后做TrimEnd
public static String GetUserNameInstagramUrl(String url)
{
Uri uri = new Uri(url);
return uri.Segments.Last().TrimEnd('/');
}
I think you have to go with trimming the '/' at the end 我认为您必须在结尾处修剪'/'
public static string GetUserNameInstagramUrl(string url)
{
Uri uri = new Uri(url);
return uri.Segments.Last().TrimEnd('/');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.