No, there's no way to do that.
John Saunders
2009-04-07 12:46:37
Why not just this?
string.Format("Toelichting: {0}", string.IsNullOrEmpty(explanation) ? "–" : explanation);
I don't think there's a way to embed this within the format string.
You can do it like this:
String.Format("Toelichting: {0}",
(String.IsNullOrEmpty(yourstr)) ? "-" : yourstr);
Not perfect but its relatively compact and readable.
If you're doing this sort of thing a lot then consider writing your own formatter so that you could write code like this...
foo = string.Format(new MyFormatter(), "Toelichting: {0:explanation}", bar);
MyFormatter would implement IFormatProvider and ICustomFormatter.
Check out this...
... which is probably more complicated than you need (as it deals with reflection and works with any object)