Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a neater way to insert a space between strings than something like " "?

Tags:

string

c#

When I write out a string combined with several strings (i.e. use stringbuilder or concat), I need to insert a space between each string. I'm often doing that like this:

StringBuilder sb = new StringBuilder();
sb.Append("a" + " " + "b");

Is there a more concise way of doing the above?

Thanks

like image 670
GurdeepS Avatar asked Dec 13 '22 14:12

GurdeepS


1 Answers

It's bizarre how many people just completely ignore the AppendFormat method on StringBuilder:

sb.AppendFormat("{0} {1}", str1, str2);
like image 118
x0n Avatar answered Jan 18 '23 07:01

x0n