Tuesday, 18 July 2006
|
String formatting
posted at
09:39 PM
|
trackback
|
|
link
I was reading the Daily Grind, as I do, and Gunderloy pointed to a blog entry by Steve Tibbet that describes how to do "string formatting in C#", as it says, although of course exactly the same formatting applies in all .NET languages.
I haven't studied it in detail, but it seems to me that a lot of what's in the blog entry is in the docs already. Admittedly, it ain't always easy to find stuff in the docs. I think we improved this somewhat for 2.0 with better indexing and cross-referencing and more examples. But anyway, for your reference (in addition to Steve's blog entry), may I remind you that the docs for string formatting are here:
Composite formatting Standard numeric formatting (examples) Custom numeric formatting (examples) Standard date formatting (examples) Custom date formatting (examples)
There's more, but that's enough for now. If you can remember these when you need 'em, they can be darn useful.
I'll remind you also that you can achieve string formatting with String.Format or better yet, an overload of the ToString method that's available in just about every class.
Strings seem to be the flavor of the week. Jeff Atwood posted something about strings in which he quotes Brad Abrams saying Brad's favorite class in .NET is String. And he notes also that Karl Seguin is of the opinion that using a format string is easier than concatenating together some convoluted string to display. That's a lesson I should be learning more thoroughly.
And for completeness's sake, Jeff also links to some other folks with thoughts on strings, including Steve Tibbet, which is where we started, I guess.
[categories]
aspnet
|