Passaggio all'ora solare 27 ottobre 2024 03:00 02:00 sposta indietro l'orologio di 1 ora (si dorme 1 ora in più)
La funzione C# permette di concatenare due parti di una url indipendentemente dal fatto che finiscano o meno con una / (slash).
Ad esempio le seguenti chiamate:
ConcatUrls("http://localhost ", "pages/default.aspx")
ConcatUrls("http://localhost/ ", "pages/default.aspx")
ConcatUrls("http://localhost ", "/pages/default.aspx")
ConcatUrls("http://localhost/ ", "/pages/default.aspx")
danno tutte come risultato: http://localhost/pages/default.aspx

C#

public static string ConcatUrls(string firstPart, string secondPart)
{
    if (firstPart.EndsWith("/") ==false)
    {
        if (secondPart.StartsWith("/") == false)
        {
            return firstPart + "/" + secondPart;
        }
        return firstPart + secondPart;
    }
    if (secondPart.StartsWith("/") == true)
    {
        firstPart = firstPart.TrimEnd(new char[] { '/' });
    }
    return firstPart + secondPart;
}
Tags:
C#236 Esempi225
Potrebbe interessarti anche: