I've tried making a string like this:
[1][2][3][4][5][6][7][8][9][10]
With this code:
string nums = "[" + string.Join("][", Enumerable.Range(1, 10)) + "]";
That, however, doesn't really look very good, so I was wondering if I could combine string.Format with string.Join, sort of like this:
string num = string.Join("[{0}]", Enumerable.Range(1, 10));
So that it wraps something around each item. However, that ends up like this:
1[{0}]2[{0}]3[{0}]4[{0}]5[{0}]6[{0}]7[{0}]8[{0}]9[{0}]10
Is there a better/easier way to do this?
Among all the solutions, I must say I prefer this
string s = string.Concat(Enumerable.Range(1, 4).Select(i => string.Format("SomeTitle: >>> {0} <<<\n", i)));
Over this
string s2 = "SomeTitle: >>>" + string.Join("<<<\nSomeTitle: >>>", Enumerable.Range(1, 4)) + "<<<\n";
Because all the formatting is done in one string, not in multiple.
string.Concat(Enumerable.Range(1,10).Select(i => string.Format("[{0}]", i)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With