I need to improve the method below.
The thing is to extract the first folder of an URL if it exists. The urls that can be pass are with domain or without domain, that is to say: http://www.xxx.com/es/test/test.aspx or http://xxx.com/es/test/ or /us/xxx/xxx.aspx.
public string ExtractURL(string url)
{
string result = "";
try
{
string[] urlSplitted = url.Split("//".ToCharArray());
//si encontramos /
if (urlSplitted.Length > 0)
{
string strFin = urlSplitted[urlSplitted.GetUpperBound(0) - 1];
//comprobamos que exista algo
if (String.IsNullOrEmpty(strFin))
{
result = url;
}
else
{
//devuelvo la url hasta /ES o /EN
result = url.Substring(0,url.ToLower().IndexOf("/" +strFin.ToLower()));
}
}
else
{
result = url;
}
}
catch
{
result = "";
}
return result;
}