I have a string pathname and an array of strings containing country extensions.
string url = "/pl/test-page/index.html";
string[] countryExtensions = {"/pl/", "/de/", "/tr/"};
What I want to achive is removing that part (/pl/ in the example) if exists in the given array.
if exists I simply want to receive the following url without repeating;
string newUrl = "/test-page/index.html";
Using that new url I want to print out some metacode only once just like below. I tried to use foreach but it then repeats the same metacode.
<link rel="alternate" hreflang="en-US" href="https://example.com/test-page/index.html" />
<link rel="alternate" hreflang="pl-PL" href="https://example.com/pl/test-page/index.html" />
<link rel="alternate" hreflang="de-DE" href="https://example.com/de/test-page/index.html" />
<link rel="alternate" hreflang="tr-TR" href="https://example.com/tr/test-page/index.html" />
How can I achieve that?
string newUrl = "/test-page/index.html";Why is the/at the start still there? Wasn't it removed when you removed/pl/?Array.ForEach(countryExtensions, x => { url = url.Replace(x, ""); });or you could set thecountryExtensions.ToList().ForEach(x => { url = url.Replace(x, ""); });Thank you for correcting me on that.