How to fill a string with repeated characters in C# ?

Here’s a small tip on using the string class better .

You can use the string class constructor to fill a string that has all the repeated characters .

For example , assume you want a string with 10 # or * symbols .

One of doing this declaring a string like this

string str = “##########”;

The other easy and best way is to use the string class constructor like below

private void Form1_Load(object sender, EventArgs e)
     string stringSymbols = new string('#', 10);


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

No Responses

  1. How to fill a string with repeated characters in C# | ProgramInDotnet August 8, 2011 Reply

Leave a Reply


Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Bing Search displays few school boards exam results
Looks like Bing now has a new feature that displays the results of various exams within Bing directl...