我有一个链接,子类别重复了很多次。如果它们在某个列表中,也只想保持重复。但也要保留链接的最后一部分 About Video Example1 Example2
www.example.com/About/About/Videos/Videos/Videos/Featured/5-great-videos
应该
www.example.com/about/videos/5-great-videos
有什么帮助吗?
这个怎么样,使用 LINQ
string str = "www.example.com/About/About/Videos/Videos/Videos/Featured/5-great-videos";
var result = str.Split('/').GroupBy(x=>x).Select(x=>x.Key).Aggregate((a,b)=>a+"/"+b);
如果您不想使用 linq:
string url = "www.example.com/About/About/Videos/Videos/Videos/Featured/5-great-videos";
List<string> urlList = new List<string>();
foreach (string urlToken in url.Split('/'))
if (!urlList.Contains(urlToken)) urlList.Add(urlToken);
url = String.Join("/", urlList.ToArray());