Exemple #1
0
        public static string Pad(this string str, int newLength, char padCharacter = ' ', PadAlignment allignment = PadAlignment.Left)
        {
            int count = str.Length;

            if (count >= newLength)
            {
                return(str.Clone().ToString());
            }

            switch (allignment)
            {
            case PadAlignment.Right:
                return((new string(padCharacter, newLength - str.Length)) + str);

            case PadAlignment.Left:
                return(str + (new string(padCharacter, newLength - str.Length)));

            case PadAlignment.Centre:
                int before = (newLength - str.Length) / 2;
                int after  = newLength - (str.Length + before);
                return((new string(padCharacter, before)) + str + (new string(padCharacter, after)));

            default:
                goto case PadAlignment.Left;
            }
        }
Exemple #2
0
 public static string Pad(this string str, int newLength, PadAlignment allignment = PadAlignment.Left)
 {
     return(Pad(str, newLength, ' ', allignment));
 }