Tales from the Crypt
-
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
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 ofString
! 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
-
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
-
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 ofString
! 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
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! :-\
-
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! :-\
-
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
Surely this should have been an extension method :)
-
Are you the one that developed this abomination? I threw up a little while reading this method X|
C'mon, I use to work with excellent teams which are prone to produce gems of that splendid quality! :)
-
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'mon, I use to work with excellent teams which are prone to produce gems of that splendid quality! :)
-
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
-
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
-
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.
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