string currentUrl = "destination/India/India/mumbai";
string[] array = currentUrl.Split('/');
string countryName = "india";
In the above example,In C# how can i check that Country name is repeating in url?
string currentUrl = "destination/India/India/mumbai";
string[] array = currentUrl.Split('/');
string countryName = "india";
In the above example,In C# how can i check that Country name is repeating in url?
you can use the Distinct method. Something like
string currentUrl = "destination/India/mumbai";
string[] array = currentUrl.Split('/');
string countryName = "india";
if (array.Distinct().Count() != array.Count())
{
Console.WriteLine("Duplicate");
}
Or you can try blow code
string currentUrl = "destination/india/india/mumbai";
string[] array = currentUrl.Split('/');
string countryName = "india";
bool r = array.Where(x => x.Equals(countryName)).Count()>1;
if(r)
{
Console.WriteLine("Duplicate");
}
"destination/destination/India/mumbai" will also result duplicate but the country name is not repeating