/egilh

Learning by doing

Smart Paster plugin for Visual Studio

Posted on Thursday, December 15, 2005 10:00 PM

Shame on me for not posting about the Smart Paster 1.1 plugin before.

In Windows Forms applications I sometimes have to show long messages explaining why an operation failed or to provide additional information. The text is usually provided by the customer or a technical writer. Cutting and pasting it directly is normally not an option as:

  • the string is impossible to read in the editor or on paper when it is too long
  • there may be formatting characters which have to be escaped

XML and other text formats with quotes in them are even worse.

Unless you use Spart Paster that is;


The Smart Paster inserts the contents in a properly formatted String builder according to the configuration options:

Building XML the brutal way with string (i.e. not using XmlWriter) becomes a piece of cake. This source string in the clipboard:

<root>
 <node attribA="a" attribB="b"/>
 <path ="c:\temp\test.txt"/>
</root>

Automagically becomes this if you paste it as a StringBuilder called builder:

StringBuilder builder = new StringBuilder(81);
builder.AppendFormat(@"{0}", Environment.NewLine);
builder.AppendFormat(@"{0}{1}", ControlChars.Tab, Environment.NewLine);
builder.AppendFormat(@"{0}{1}", ControlChars.Tab, Environment.NewLine);
builder.AppendFormat(@"
{0}", Environment.NewLine);

All quotes and strange characters taken care of. What more can you ask for?




Feel free to drop a few cents in the tip jar if this post saved you time and money

Post Comment
Title
 

Name
 

Url

Protected by Clearscreen.SharpHIPEnter the code you see:
Comment