Пример #1
0
        public static string Justify(string data, string _space, int space, JustifyIs flag = JustifyIs.left)
        {
            data = data.Trim();
            int half  = space / 2;
            int width = data.Length / 2;

            switch (flag)
            {
            case JustifyIs.left: return((space >= data.Length) ? (data + _space).Remove(space) : data.Remove(space - 3) + "...");

            case JustifyIs.right: return((space >= data.Length) ? _space.Remove(space - data.Length) + data : data.Remove(space - 3) + "...");

            case JustifyIs.center: return((space >= width) ? (_space.Remove(half - width) + data + _space).Remove(space) : data.Remove(space - 3) + "...");

            default: return(data);
            }
        }
Пример #2
0
        public static string Justify(string data, int check, string _space, int space, JustifyIs flag = JustifyIs.left)
        {
            int c = data.Split('.').Count();

            if (check == 1 && c > 1)
            {
                int zeros = (3 - data.Split('.')[1].Length);
                for (int i = 0; i < zeros; i++)
                {
                    data += "0";
                }
            }
            else if (check == 1 && c == 1)
            {
                data += ".000";
            }
            int half  = space / 2;
            int width = data.Length / 2;

            switch (flag)
            {
            case JustifyIs.left: return((space >= data.Length) ? (data + _space).Remove(space) : data.Remove(space - 3) + "...");

            case JustifyIs.right: return((space >= data.Length) ? _space.Remove(space - data.Length) + data : data.Remove(space - 3) + "...");

            case JustifyIs.center: return((space >= width) ? (_space.Remove(half - width) + data + _space).Remove(space) : data.Remove(space - 3) + "...");

            default: return(data);
            }
        }