Archive

Posts Tagged ‘Formatting’

A simple visual divider.

May 29th, 2011 No comments

(Another snippet I originally posted to CodeKeep.)

In perl, I could write "=" x80 to create a visual separator in my debug statements or report headers.  Here is an equally crisp syntax to do the same in C#. 

Code:

 

Environment.NewLine + String.Empty.PadRight(80,’=') + Environment.NewLine;

 

Notes:

This idea also works for strings that need to be trimmed to a specific length (think fixed width output files).  Take the existing string, pad it to the desired length, then chop off the rest via a substring. 

 

myString.PadRight(80 ,’ ‘).Substring(0, 80).TrimEnd(new char[] {‘ ‘});

Tags: , ,

Setting an Excel 2007 gradient background

December 9th, 2009 No comments

Description:
Set a cell’s background color to a vertical gradient using two user-defined colors.

Code: Read more…

Tags: , , ,

Formating a list of items into a sentence with commas and the ampersand.

December 9th, 2009 No comments

Description:
I need to link an list of (string) items into a sentence at runtime. Here’s a short and simple method to handle the commas and ampersand.

Code:

Read more…

Tags: ,