假设我们在页面上www.abc.com/apple-store
那么如何apple-store
在asp C#代码中获取字符串。
存储到另一个变量中。
您可以使用 string.last() 来提取它。
string lastPartUrl =HttpContext.Current.Request.Url.AbsoluteUri.Split('/').Last();
您可以在字符串变量中获取 url。此外,您可以实现以下逻辑,将值保存在变量中。
string str = "www.abc.com/apple-store";
string result = "";
int i= 0;
int len = str.Length;
//Get the index of the character
i = str.IndexOf('/');
//store the result in the variable
result = str.Substring(i+1,len-i-1);
Console.WriteLine("Resultant:- {0}", result);`
希望这个对你有帮助。