What's new

.NET Position logging method

Cuddz

Cuddz

Enthusiast
Messages
117
Reaction score
6
Points
70
Sin$
0
I made this a loooong time ago and decided to release it because I'm tired of seeing people using tabs to customize the position of text.
(this code is for a console app, you can alter it to work with what ever you want)

Code:
enum Positions
        {
            Left,
            Right,
            Middle
        }
static void Log(string text, Positions position)
        {
            int middle = 80;
            int right = 80;

            if (position == Positions.Left)
             Console.WriteLine(text);
            if (position == Positions.Right)
            {
                //Get total number of characters
                int length = right - text.Length;
                // -80
                //place remaining in front of characters
                string space = string.Concat(Enumerable.Repeat(" ", length));
                Console.Write(space + text);
            }
            if (position == Positions.Middle)
            {
                //Get total number of characters
                //-80
                int length = (middle - text.Length) / 2;
                //remaining /2
                string space = string.Concat(Enumerable.Repeat(" ", length));
                Console.WriteLine(space + text);
            }
        }
Call it like so:
Log("gucci", Positions.Middle);

I know this is not clean code and I don't really care. You can clean it up yourself, I was experimenting with enumerators and more ****. As I said, I made this a loooooong time ago
 
Top Bottom
Login
Register