views:

132

answers:

3

This may be a simple question since it seems such an obvious tool for any web dev..

I currently use a free web-based thing when I need to encode strings, but I was curious to know if anyone knows of a plugin for VS that will allow you to HTML encode text in the Text Editor?

A: 

Plug-in, NO, but code? Why don't you just reference System.Web and...

System.Web.HttpUtility.HtmlEncode("input string");

You could easily build a console app which does that.

"".Replace("<","&lt;") // this is usually enough to escape HTML

...but maybe you want to encode everything so that your output is ASCII?

John Leidegren
Of course I am aware of the code-based way of doing it, but I am looking for a way of quickly encoding text I paste into the editor. :)
Rob Cooper
I guess the easiest way then would be to just write that app and hot key it as an external app you could use it to grab, actually replace the clip board. That way you copy text (put in clipboard) hot key external tool and voila paste. That's three trivial steps an no hefty VS integration stuff.
John Leidegren
Nice idea, wonder what it will be like to create a VS2010 plugin.. Apparantly it is much easier to create plugins in VS2010 for the text editor..
Rob Cooper
Yeah, I think it's gonna be awesome, and that's really important, the IDE usually doesn't provide you with everything you need, but if you build it with great extendability in mind, I think a lot of people will be a lot happier. Me included.
John Leidegren
I'm totally physced about VS2010, there's like a million things I wanna do with the text editor.
John Leidegren
+1  A: 

Yes there is a simple "plugin".

Goto "Tools" -> Macro Explorer -> Create new macro.

Sub EncodeHtml() DTE.ActiveDocument.Selection.Text = System.Web.HttpUtility.HtmlEncode(DTE.ActiveDocument.Selection.Text) End Sub

Assign a hotkey. There you go.

A: 

I only know this because I just found the answer and earlier while googling to find the answer I ran across this post.

If you're developing a console app in Visual Studio 2008 the System.Web Name Space isn't available. But, if you 'Add Reference' you can select the System.Web Name Space which will allow you to use the httputility and use the built in htmlencode and htmldecode.

Mikecancook