Remember - this is supposed to be C#...
-
/// /// Fuegt solange Blanks an den String an, bis die /// Laenge length erreicht wird. /// /// /// /// public static string AddBlanks(string inputString, int length) { string outString = inputString; while (outString.Length < length) { outString = outString + " "; } return outString; } Not only a memory issue (using string instead of stringbuilder), but why have the gods^W BCL group created the string.PadRight(lenth, ' ') method? What do you think? :laugh: Cheers, Juergen
-
/// /// Fuegt solange Blanks an den String an, bis die /// Laenge length erreicht wird. /// /// /// /// public static string AddBlanks(string inputString, int length) { string outString = inputString; while (outString.Length < length) { outString = outString + " "; } return outString; } Not only a memory issue (using string instead of stringbuilder), but why have the gods^W BCL group created the string.PadRight(lenth, ' ') method? What do you think? :laugh: Cheers, Juergen
6o`clock wrote:
Not only a memory issue (using string instead of stringbuilder), but why have the gods^W BCL group created the string.PadRight(lenth, ' ') method? What do you think?
I would think someone is learning C#. I can see me making mistakes of exactly the same type. Ok, I know about stringbuilder, but there are whole top-level namespaces I never used. I certainly do not know their functions by heart.
Failure is not an option - it's built right in.
-
6o`clock wrote:
Not only a memory issue (using string instead of stringbuilder), but why have the gods^W BCL group created the string.PadRight(lenth, ' ') method? What do you think?
I would think someone is learning C#. I can see me making mistakes of exactly the same type. Ok, I know about stringbuilder, but there are whole top-level namespaces I never used. I certainly do not know their functions by heart.
Failure is not an option - it's built right in.
My colleague and I had an interesting discussion about this. According to us, there are two types of programmers out there. The first type thinks 'This is such a common thing to do, someone MUST have included it' and therefor ends up using the PadString method. The second type just churns away without seconds thoughts and ends up with the originally posted code. The funny thing is that 9 out of 10 times people tend to refactor these snippits into a utilities class, calling the method 'PadString' :cool: