Eddie Garmon's Weblog

some architecture, some c#

Quickest way to create a repeating string in c#?

int repeatCount = 10;
string value = "hello world.";
string repeated = string.Join(value, new string[repeatCount + 1]);
Console.WriteLine(repeated);

Comments

Alex said:

How about ...

public static string RepeatString(string
stringToRepeat, int repeatCount)
{
StringBuilder sb = new
StringBuilder(stringToRepeat.Length *
repeatCount);

for (int i=0; i < repeatCount; i++)
sb.Append(stringToRepeat);

return sb.ToString();
}
# January 12, 2005 6:29 PM

Eddie Garmon said:

I thought so too until I profiled it. You would be supprised at the performance gain in string.Join(), even if you create the StringBuilder with enough memory to hold the final string.
# January 12, 2005 7:10 PM

bigjuju said:

that's purty clever, mister. i'm always up for new string manipulation tricks.
# February 5, 2005 5:08 PM

Avi Nahir said:

Wow! You're using the string as a separator to join empty strings. That's cool and twisted!

# November 21, 2007 9:51 AM

myourshaw said:

how about

string str = new string('?',99).Replace("?","foo")

ugly, but it works

# February 13, 2009 11:51 PM

Kassia said:

Good Day. Absolute faith corrupts as absolutely as absolute power. Help me! Please help find sites for: Low cost stock trading. I found only this - <a href="www.justiceplanbook.com/.../StockTrading">trade stocks online</a>. Amount day, or right order, is a execution accessibility in which months are only that have now been understanding off a fraud internet or existing off a intelligence credit, stock trading. In 1967, she sold a capital, stock trading. With love ;-), Kassia from Tuvalu.

# March 24, 2010 10:47 AM

seo资源 said:

Hey, I am the digi consumer. Why increasing daylight savings time promo just logical till 31st august? Why not consider to prospects who have miss that possibility?

# October 23, 2012 3:40 PM

icons library said:

 You were visited with an excellent idea

<a href="windows2012icons.com/.../icon-for-disclaimer-b2">icon for disclaimer</a>

# October 31, 2012 2:01 PM

icons collection said:

<a href=monday-monkeys.co.uk/.../viewtopic.php Certainly. All above told the truth. We can communicate on this theme. Here or in PM.</a>

# November 4, 2012 1:40 AM

icon set said:

[url=hybridbulgaria.com/viewtopic.php] I know one more decision[/url]

# November 4, 2012 3:28 PM

icon collection said:

[url=forum.asa.az/showthread.php] I think, that you are not right. I can prove it.[/url]

# November 5, 2012 10:55 AM

web icons said:

P.S. Please review our <a href="http://windows-icon-editor.com">design portfolio</a> for Doors2012.

Social Bookmarking Icons

Perhaps all of you guys noticed that most popular web sites and blogs have added a set of small icons in the beginning or in the end of every article, blogpost, YouTube video, music or video file. Some of these icons look familiar to you as you use relevant websites every day (for example, Twitter or Facebook), while others are still unknown. These icons are called social bookmarking widgets.Imagine such a situation. You have read an article or a blog post which you particularly liked and found interesting. Naturally, you want your friends to read this article as well. But you wouldn't e-mail it to all of them or use chat programs for these purposes. Why not use social media? All of your friends spend so much time in social networking and bookmarking websites. You only have to click on a relevant icon and you're automatically redirected to the web site you have chosen in order to share the link with the world.Some webmasters only use a few icons. As a rule, these are most popular social networking and bookmarking websites, such as Twitter, FaceBook, MySpace, Digg, Delicious and others. In some cases the number of icons may reach 20 or even more. Well, you never know what social bookmarking and networking websites your visitors and readers are using. So, it is slways better to give them a choice.But why install these widgets? How does a website owner benefit? First and foremost, this is done for convenience of web site visitors and potential customers. Social bookmarking and networking widgets are a must for every respectable web site. But a great advantage is that web site owners also benefit from social bookmarking icons.Every time a visitor bookmarks a page from your website you get a relevant back link published at a respectable site with high PR. The more bookmarks you've got the better position of your website in search engines might be. In such a way both web site visitors and owners benefit from installment of social networking and bookmarking widgets.

# December 13, 2012 10:46 PM

igeduuwwum@gmail.com said:

Thanks for the great article..

# February 23, 2013 1:59 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)