Create string of repeated char

  • Thread starter Thread starter Erick Sasse
  • Start date Start date
E

Erick Sasse

This is not really a C# question, but I'm not sure which is the best
group to post it. Please, point me to the right one.

What's the best way to create a string from a repeated char? For
instance, I pass char = "*" and size = 5, and get a string = "*****".

I could write a function to loop size times and append to a
StringBuilder, but maybe there is something ready in the framework.

Thanks.
 
Erick Sasse said:
This is not really a C# question, but I'm not sure which is the best
group to post it. Please, point me to the right one.

What's the best way to create a string from a repeated char? For
instance, I pass char = "*" and size = 5, and get a string = "*****".

I could write a function to loop size times and append to a
StringBuilder, but maybe there is something ready in the framework.

One of the constructors for string takes a character and an int as parameters.
It does what you want.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top