Create string of length X

  • Thread starter Thread starter Martin Rosén-Lidholm
  • Start date Start date
M

Martin Rosén-Lidholm

When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm
 
Martin Rosén-Lidholm said:
When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm
How about padding?
 
Hmmm, how about:

class Builder
{
static string MakeString(int iLength)
{
StringBuilder sb = new StringBuilder();

for(int i = 0; i < iLength; i++)
{
sb.Append('x');
}

return sb.ToString();
}
}

so, string str = Builder.MakeString(5); gives you: xxxxx
 
Back
Top