You are viewing our Forum Archives. To view or take place in current topics click here.
C# position logging method
Posted:

C# position logging methodPosted:

0xCuddz
  • New Member
Status: Offline
Joined: Aug 31, 20149Year Member
Posts: 18
Reputation Power: 0
Status: Offline
Joined: Aug 31, 20149Year Member
Posts: 18
Reputation Power: 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)

    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 even close to 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
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.