using format strings or the equivalent

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi all,

I' like to now how to use formatting strings for certain or all methods in
..net ..

I keep coming across problems such as displaying a timespan and getting
hours, mins date and all the milliseconds

back in the old C days you could put together a format string in your good
old printf command ... and it seems you can do that in c# .. but apart from
a few set commands I cant find the mechanism that allows complete control
over the strings.

I thought methods such as myTimeSpan.ToString(" some format string ") ..
would be a good place to have them .. but alas ... and it also seems that
nto all the toString() methods seem to work the same.

sometime giving it a (T) or a (C) is not enough control .... the .Net docs
are extensive and unless you already know what your looking for .... well
....

any starting points ... such things as "hh:mm:ss" .. or these sort of things
?

regards Bob
 
Bob said:
I' like to now how to use formatting strings for certain or all methods in
..net ..

I keep coming across problems such as displaying a timespan and getting
hours, mins date and all the milliseconds

back in the old C days you could put together a format string in your good
old printf command ... and it seems you can do that in c# .. but apart from
a few set commands I cant find the mechanism that allows complete control
over the strings.

I thought methods such as myTimeSpan.ToString(" some format string ") ..
would be a good place to have them .. but alas ... and it also seems that
nto all the toString() methods seem to work the same.

..NET has exactly what you are looking for with the ToString() method. To
see the formatting strings, look in the documentation for the ToString()
method in the derived class. e.g., to see how to format dates, look up the
"DateTime.ToString method" in the .NET documentation.

In addition, here is an handy reference on string formatting in .NET:

http://blog.stevex.net/index.php/string-formatting-in-csharp/
 
Back
Top