{"id":30,"date":"2013-11-03T14:45:00","date_gmt":"2013-11-03T14:45:00","guid":{"rendered":"http:\/\/tpodolak.com.hostingasp.pl\/blog\/2013\/11\/03\/generating-string-consisting-of-the-same-character\/"},"modified":"2016-01-30T23:45:30","modified_gmt":"2016-01-30T23:45:30","slug":"generating-string-consisting-of-the-same-character","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2013\/11\/03\/generating-string-consisting-of-the-same-character\/","title":{"rendered":"Generating string consisting of the same character"},"content":{"rendered":"<p>Recently I&#8217;ve been asked by friend of mine, how to generate string consisting of 50 commas. I came up with these three code snippets:<\/p>\n<pre lang=\"csharp\">\r\nvar repeat = string.Join(string.Empty, Enumerable.Repeat(\",\", 50));\r\nvar aggregate = Enumerable.Range(1, 50).Aggregate(new StringBuilder(), \r\n                                                 (acc, seed) => acc.Append(\",\")).ToString();\r\nvar usingArray = string.Join(\",\", new string[51]);\/\/must be 51, separator is not inserted after last index\r\n<\/pre>\n<p>Although all of these lines produce appropriate outcome, it&#8217;s seemed to me that there is some simpler way to accomplish this task. After a little bit of searching, it turned out, that it is possible to generate string consisting of same characters using one of string&#8217;s constructors<\/p>\n<pre lang=\"csharp\">\r\nvar usingConstructor = new string(',', 50);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I&#8217;ve been asked by friend of mine, how to generate string consisting of 50 commas. I came up with these three code snippets: var repeat = string.Join(string.Empty, Enumerable.Repeat(&#8220;,&#8221;, 50)); var aggregate = Enumerable.Range(1, 50).Aggregate(new StringBuilder(), (acc, seed) => acc.Append(&#8220;,&#8221;)).ToString(); var usingArray = string.Join(&#8220;,&#8221;, new string[51]);\/\/must be 51, separator is not inserted after last index [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[207],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-string","tag-string"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":2,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":503,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/30\/revisions\/503"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}