471,306 Members | 1,432 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Create string of repeated char

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
Feb 1 '06 #1
3 2135
"Erick Sasse" <es****@newsgroups.nospam> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
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
Feb 1 '06 #2
String s;
s.PadRight(5, '*');

"Erick Sasse" <es****@newsgroups.nospam> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
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

Feb 1 '06 #3
Bill Butler wrote:
One of the constructors for string takes a character and an int as
parameters. It does what you want.


Thanks Bill!

--
Erick Sasse
Feb 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Marcio Kleemann | last post: by
5 posts views Thread by MaSTeR | last post: by
9 posts views Thread by c_beginner | last post: by
14 posts views Thread by Hugh Janus | last post: by
6 posts views Thread by Bill Cunningham | last post: by
20 posts views Thread by sophia | last post: by
1 post views Thread by TrippW06 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.