"Unescape my Strings" - C#

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

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


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
        If pane Is Nothing Then _
          pane = output.OutputWindowPanes.Add(winName)

      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