Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Tales from the Crypt

Tales from the Crypt

Scheduled Pinned Locked Moved The Weird and The Wonderful
pythoncomlearning
13 Posts 10 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

    public static string PadStrg(string value, int length, char padValue, pad Pad)
    {
    if (value == null)
    value = string.Empty;

            StringBuilder sb = new StringBuilder();
            string returnString = string.Empty;
            if (Pad == pad.Right)
            {
                sb.Append(value.Trim());
                sb.Append(padValue, length);
                returnString = sb.ToString(0, length);
            }
            else
            {
                sb.Append(padValue, length);
                sb.Append(value.Trim());
                returnString = sb.ToString(sb.Length - length, length);
            }
            return returnString;
        }
    

    Marc

    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

    M Richard DeemingR F W L 7 Replies Last reply
    0
    • M Marc Clifton

      This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

      public static string PadStrg(string value, int length, char padValue, pad Pad)
      {
      if (value == null)
      value = string.Empty;

              StringBuilder sb = new StringBuilder();
              string returnString = string.Empty;
              if (Pad == pad.Right)
              {
                  sb.Append(value.Trim());
                  sb.Append(padValue, length);
                  returnString = sb.ToString(0, length);
              }
              else
              {
                  sb.Append(padValue, length);
                  sb.Append(value.Trim());
                  returnString = sb.ToString(sb.Length - length, length);
              }
              return returnString;
          }
      

      Marc

      V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

      M Offline
      M Offline
      MarkTJohnson
      wrote on last edited by
      #2

      :wtf: We'll pray for you.

      1 Reply Last reply
      0
      • M Marc Clifton

        This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

        public static string PadStrg(string value, int length, char padValue, pad Pad)
        {
        if (value == null)
        value = string.Empty;

                StringBuilder sb = new StringBuilder();
                string returnString = string.Empty;
                if (Pad == pad.Right)
                {
                    sb.Append(value.Trim());
                    sb.Append(padValue, length);
                    returnString = sb.ToString(0, length);
                }
                else
                {
                    sb.Append(padValue, length);
                    sb.Append(value.Trim());
                    returnString = sb.ToString(sb.Length - length, length);
                }
                return returnString;
            }
        

        Marc

        V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Well, it's not like String.PadLeft[^] and String.PadRight[^] have been part of .NET since v1, is it? :doh: And look how many characters you save by using Strg instead of String! The code is smaller, and therefore it must be more efficient. :rolleyes:


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        B 1 Reply Last reply
        0
        • M Marc Clifton

          This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

          public static string PadStrg(string value, int length, char padValue, pad Pad)
          {
          if (value == null)
          value = string.Empty;

                  StringBuilder sb = new StringBuilder();
                  string returnString = string.Empty;
                  if (Pad == pad.Right)
                  {
                      sb.Append(value.Trim());
                      sb.Append(padValue, length);
                      returnString = sb.ToString(0, length);
                  }
                  else
                  {
                      sb.Append(padValue, length);
                      sb.Append(value.Trim());
                      returnString = sb.ToString(sb.Length - length, length);
                  }
                  return returnString;
              }
          

          Marc

          V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

          F Offline
          F Offline
          Foothill
          wrote on last edited by
          #4

          Just looking at it is giving me a headache.

          if (Object.DividedByZero == true) { Universe.Implode(); } Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016

          1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Well, it's not like String.PadLeft[^] and String.PadRight[^] have been part of .NET since v1, is it? :doh: And look how many characters you save by using Strg instead of String! The code is smaller, and therefore it must be more efficient. :rolleyes:


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            PadLeft and PadRight produce different result: if the input value is longer than the desired length, they won't cut it down. That's a great advantage of this gem! :-\

            J 1 Reply Last reply
            0
            • B Bernhard Hiller

              PadLeft and PadRight produce different result: if the input value is longer than the desired length, they won't cut it down. That's a great advantage of this gem! :-\

              J Offline
              J Offline
              Jon McKee
              wrote on last edited by
              #6

              Are you the one that developed this abomination? I threw up a little while reading this method X|

              B 1 Reply Last reply
              0
              • M Marc Clifton

                This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

                public static string PadStrg(string value, int length, char padValue, pad Pad)
                {
                if (value == null)
                value = string.Empty;

                        StringBuilder sb = new StringBuilder();
                        string returnString = string.Empty;
                        if (Pad == pad.Right)
                        {
                            sb.Append(value.Trim());
                            sb.Append(padValue, length);
                            returnString = sb.ToString(0, length);
                        }
                        else
                        {
                            sb.Append(padValue, length);
                            sb.Append(value.Trim());
                            returnString = sb.ToString(sb.Length - length, length);
                        }
                        return returnString;
                    }
                

                Marc

                V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                W Offline
                W Offline
                Wastedtalent
                wrote on last edited by
                #7

                Surely this should have been an extension method :)

                1 Reply Last reply
                0
                • J Jon McKee

                  Are you the one that developed this abomination? I threw up a little while reading this method X|

                  B Offline
                  B Offline
                  Bernhard Hiller
                  wrote on last edited by
                  #8

                  C'mon, I use to work with excellent teams which are prone to produce gems of that splendid quality! :)

                  J 1 Reply Last reply
                  0
                  • M Marc Clifton

                    This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

                    public static string PadStrg(string value, int length, char padValue, pad Pad)
                    {
                    if (value == null)
                    value = string.Empty;

                            StringBuilder sb = new StringBuilder();
                            string returnString = string.Empty;
                            if (Pad == pad.Right)
                            {
                                sb.Append(value.Trim());
                                sb.Append(padValue, length);
                                returnString = sb.ToString(0, length);
                            }
                            else
                            {
                                sb.Append(padValue, length);
                                sb.Append(value.Trim());
                                returnString = sb.ToString(sb.Length - length, length);
                            }
                            return returnString;
                        }
                    

                    Marc

                    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Actually, I learned something: hadn't noticed the .Append "repeater" before. Maybe he's really an idiot savant.

                    "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                    1 Reply Last reply
                    0
                    • B Bernhard Hiller

                      C'mon, I use to work with excellent teams which are prone to produce gems of that splendid quality! :)

                      J Offline
                      J Offline
                      Jon McKee
                      wrote on last edited by
                      #10

                      My condolences :rose:

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

                        public static string PadStrg(string value, int length, char padValue, pad Pad)
                        {
                        if (value == null)
                        value = string.Empty;

                                StringBuilder sb = new StringBuilder();
                                string returnString = string.Empty;
                                if (Pad == pad.Right)
                                {
                                    sb.Append(value.Trim());
                                    sb.Append(padValue, length);
                                    returnString = sb.ToString(0, length);
                                }
                                else
                                {
                                    sb.Append(padValue, length);
                                    sb.Append(value.Trim());
                                    returnString = sb.ToString(sb.Length - length, length);
                                }
                                return returnString;
                            }
                        

                        Marc

                        V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                        K Offline
                        K Offline
                        KarstenK
                        wrote on last edited by
                        #11

                        Search for other gems of this misunderstood genius. This code shouldnt get published. :~

                        Press F1 for help or google it. Greetings from Germany

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          This code just leaves me speechless. It's wrong for so many reasons, and shouldn't actually even exist.

                          public static string PadStrg(string value, int length, char padValue, pad Pad)
                          {
                          if (value == null)
                          value = string.Empty;

                                  StringBuilder sb = new StringBuilder();
                                  string returnString = string.Empty;
                                  if (Pad == pad.Right)
                                  {
                                      sb.Append(value.Trim());
                                      sb.Append(padValue, length);
                                      returnString = sb.ToString(0, length);
                                  }
                                  else
                                  {
                                      sb.Append(padValue, length);
                                      sb.Append(value.Trim());
                                      returnString = sb.ToString(sb.Length - length, length);
                                  }
                                  return returnString;
                              }
                          

                          Marc

                          V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                          C Offline
                          C Offline
                          cjb110
                          wrote on last edited by
                          #12

                          I assume this is from a older codebase that was blindly converted to .NET, I can't imagine anyone the knows they should use StringBuilder but not that Padding strings is built into to .NET.

                          M 1 Reply Last reply
                          0
                          • C cjb110

                            I assume this is from a older codebase that was blindly converted to .NET, I can't imagine anyone the knows they should use StringBuilder but not that Padding strings is built into to .NET.

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #13

                            cjb110 wrote:

                            I can't imagine anyone the knows they should use StringBuilder but not that Padding strings is built into to .NET.

                            Sadly, this was code written in the last couple years, outsourced to some Indian devs. Marc

                            V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups