Tuesday, November 22, 2011

Generate repeating strings with LINQ

I ran across a helpful snipped for generating repeating strings with linq today.  I needed to do something similar to the following (in python):

>>> 'chris' * 5
'chrischrischrischrischris'

a comment on Igor Ostrovsky's blog provided the answer


string.Join(string.Empty, Enumerable.Repeat("chris", 5).ToArray());

Enumerable.Repeat() to the rescue!

0 comments: