如何将URL拆分为字符串数组

Si8*_*Si8 1 c# asp.net

我希望能够获得当前页面的URL并从最后一次提取到最后一次出现 /

例如,如果我的URL是这样的: http://myintranet/guidelines/Home/Pages/mymed.aspx

我想提取mymed.

到目前为止我有这个:

string strEntity = HttpContext.Current.Request.Url.AbsolutePath;
Label2.Text = strEntity;
Run Code Online (Sandbox Code Playgroud)

显示:

/guidelines/Home/Pages/mymed.aspx
Run Code Online (Sandbox Code Playgroud)

我试图使用,Split("\\").Last();但这不适用于它,并说不能将字符串[]分配给字符串...

Tho*_*que 8

您可以使用该类中的GetFileNameWithoutExtension方法System.IO.Path:

var uri = HttpContext.Current.Request.Url;
string fileName = Path.GetFileNameWithoutExtension(uri.AbsolutePath);
Run Code Online (Sandbox Code Playgroud)