Friday, July 21, 2006 11:38 AM
Geoff
String manipulation in .NET
It seems to be string week in .NET blog land. I thought I'd plop this
link to the API docs and other blog articles in here for my own sake.
Mike mentions using format strings instead of concatenation. It's a habit I've been into for a while. Moreso than using string builders, which I really need to do more often, instead of being a (bad) lazy programmer and concatenating stuff.
I like the control you get doing:
string var = string.Format("{0} {1} - {3}", blah, foo, bar);over:
string var = blah + " " + foo + " - " + bar;and it's far less verbose than:
StringBuilder sb = new StringBuilder();
sb.Append(blah);
sb.Append(" ");
sb.Append(foo);
sb.Append(" - ");
sb.Append(bar);
string var = sb.ToString();Don't you think?