Formatting Strings in C#

By xerocube | January 29, 2007

This article provides a great overview for formatting strings in C#. As I have been dabbling with a new GUI for my database, I’ve been having fits with formatting certain types of strings. This site helped me find my way…

 String Formatting in C#

Of particular help were these examples:

String.Format(”{0:$#,##0.00;($#,##0.00);Zero}”, value);

This will output “$1,240.00″ if passed 1243.50. It will output the same format but in parentheses if the number is negative, and will output the string “Zero” if the number is zero.

String.Format(”{0:(###) ###-####}”, 8005551212);

This will output “(800) 555-1212″.

If you have any questions about string formatting, or pretty much anything related, drop by the Forum and ask it there. It’s an easier place to talk than in the comments section here.

Happy Coding!

Topics: Code | No Comments »

Comments

Archives

Blogroll

RockinMedia