【发布时间】:2019-01-03 13:11:38
【问题描述】:
我需要在“home”之后提取 URL 的其余部分
例如,网址可以是
https://www.example.com/site/country/home/products
https://www.example.com/site/country/home/products/consumer
https://www.example.com/site/country/home/products/consumer/kids
url“site”、“country”中的关键字可能会改变。
我只需要输出:
/products
/products/consumer
/products/consumer/kids
我尝试使用正则表达式,但在上述情况下不起作用
【问题讨论】:
-
找到“/home/”的第一个索引并取其后的子字符串?
-
你试过什么正则表达式?另外,为什么不直接使用String.IndexOf()?
-
Something like this should work
string rest = url.Substring(url.IndexOf("/products"));