Is there a succinct way (i.e. not a for loop) to create a string of a specified length? Doesn't matter what is in the string.
+20
A:
You can use the string
constructor that takes a char
and an int
. It creates a string
instance with the char
repeated the specified number of times.
bdukes
2009-08-21 16:49:35
+12
A:
As bdukes mentions there's constructor, that takes a char and an int. That will construct a string of the given length filled with the char.
However, keep in mind, that strings are immutable in .NET, so if you want to create a specific string buffer, you should use StringBuilder
instead.
Brian Rasmussen
2009-08-21 16:52:03
A:
why would you want to create a string if you dont want to control what the value of the string would be?
I would suggest using a StringBuilder and using the constructor that takes an int
Petoj
2009-08-21 16:55:54
For unit testing edge cases
Jeremy
2009-08-21 16:57:39