Repeating characters into strings in C# and Delphi (via: .net – Best way to repeat a character in C# – Stack Overflow)
Posted by jpluimers on 2012/06/26
Switching back and forth between mainly Delphi and C#, sometimes it is hard to remember which idiom works best in each environment.
Recently, I had to dupe a lot of tab characters for some Tab-Delimited interface to an archaic system.
I remembered the Delphi idiom: use the DupeString function as about Delphi explains (yes, I know: it dupes more than just characters).
In C#, these work best for me:
- for string use the String constructor that accepts a character and a count
- for StringBuilder, us the Append method that accepts a character and a count
Small code sample of the first way (thanks CMS):
static string Tabs(int n)
{
return new String('\t', n);
}
–jeroen
via: .net – Best way to repeat a character in C# – Stack Overflow.
Oh BTW: I have reduced my StackOverflow presence. It looks like the success of StackOverflow made them instantiate many moderators. A lot of those moderators work under the mantra “we follow the rules strictly, and favour punishment over encouragement” (some even talk about “changing heritage“). That’s a real pity, as I see a lot of StackOverflow users get scared by the very active downvoting, question/answer closing and even deletion of material that is in essence valuable, if it were edited up a bit. Deleting content is always bad, as it increases the link rot that StackOverflow are trying to prevent in questions/answers as per their FAQ. Links are the foundation of the web.
Alas, devoting real attention to the quality of StackOverflow requires putting real energy in it, which for some of the moderators seems to be too much to ask.






A. Bouchez said
On Delphi, I would better use “StringOfChar” instead, which is dedicated to repeating characters, is available in all Delphi versions, and part of System.pas.
About SO, I feel a bit the same. But we have to face the fact that some questions are very vague. Sometimes, you’ll have to guess what was asked. Need to be crystal-ball gazers. ;)
jpluimers said
Something went wrong with approving and replying to your earlier comment. After that I was on the road.
So here is the reply again: Thanks for the `StringOfChar` tip. Never too old to learn (:
Note I do appreciate moderators improving vague answers, but the way some moderators treat perfectly valid questions, and retro-actively kill questions (including valueable answers) just to improve perceived average question quality is beyond my understanding.
abouchez said
I’ve just voted up this SO question: http://stackoverflow.com/questions/11215216/free-vcl-components-for-delphi-7-and-mysql
Some are still closing faster than answering!
jpluimers said
I voted for reopen.
Eric said
I had noticed that trend at SO too, which came on top of the IMHO annoying one of splitting stuff across other sites (programmersexchange, etc.) which need separate registration, don’t have easy merging/redirection of questions, etc.
Time is ripe for a new service to emerge I guess.