"Unescape my Strings" - C#

1 post / 0 new
benzzon
benzzon's picture
"Unescape my Strings" - C#

"Unescape my Strings", when using "immediate window" in Visual Studio..

http://devlicio.us/blogs/sergio_pereira/archive/2008/05/07/unescape-my-strings.aspx

To create the macro:

- View » Other Windows » Macro Explorer
- Right-click "My Macros" » New Module
- Call the new module "Unescape"
- Add the following sub


Public Module Unescape
  Public Sub UnescapeText()
    Dim winName As String = "Unescaped"
    Dim win As Window
    Dim output As OutputWindow
    Dim pane As OutputWindowPane = Nothing

    If DTE.ActiveWindow IsNot Nothing AndAlso _
      DTE.ActiveWindow.Selection IsNot Nothing Then

      Dim text As String = DTE.ActiveWindow.Selection.Text

      If Not String.IsNullOrEmpty(text) Then

        text = text.Replace("\t", vbTab) _
          .Replace("\r\n", vbCrLf) _
          .Replace("\n", vbCrLf) _
          .Replace("\r", vbCrLf) _
          .Replace("\""", """")

        win = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        output = win.Object

        For Each p As OutputWindowPane In output.OutputWindowPanes
          If p.Name = winName Then
            pane = p
            Exit For
          End If
        Next
        If pane Is Nothing Then _
          pane = output.OutputWindowPanes.Add(winName)

        win.Activate()
        pane.Activate()
        pane.OutputString(text)
      End If
    End If
  End Sub
End Module

 
 
 
 
To add a shortcut:
 
- Tools » Options » Environment » Keyboard
- Show commands containing: unescape
- Select the macro when it gets listed
- Add a Global shortcut, I used Ctrl+Alt+U