2010-05-24 60 views

回答

2

這種工具絕對屬於自己動手類別。啓動一個新的Windows窗體應用程序。粘貼下面顯示的代碼。在桌面上放置一個程序快捷方式。要使用它,請將文件從資源管理器拖到窗體上。切換到Visual Studio並鍵入Ctrl + V。

Public Class Form1 
    Public Sub New() 
     InitializeComponent() 
     Me.AllowDrop = True 
    End Sub 

    Protected Overrides Sub OnDragEnter(ByVal e As DragEventArgs) 
     If e.Data.GetDataPresent("FileDrop") Then e.Effect = DragDropEffects.Copy 
    End Sub 

    Protected Overrides Sub OnDragDrop(ByVal e As DragEventArgs) 
     Dim files = DirectCast(e.Data.GetData("FileDrop", False), String()) 
     Dim txt As New System.Text.StringBuilder 
     Dim lines = System.IO.File.ReadAllLines(files(0)) 
     For ix As Integer = 0 To lines.Length - 1 
      txt.Append("""" + lines(ix).Replace("""", """""") + """") 
      If ix < lines.Length - 1 Then txt.AppendLine(" & _") 
     Next 
     Clipboard.SetText(txt.ToString()) 
    End Sub 
End Class 

更好的捕鼠器是將文件添加爲資源,而不是硬編碼文本。

+0

你也可以使這個VS加載項。 – 2010-05-24 21:47:31

+0

感謝漢斯的代碼 – 2010-05-28 20:10:25

+0

歡迎您。連續六個雙引號是個人第一:) – 2010-05-28 20:42:04

1

這是你在找什麼?

Dim testString As String = "line1" & vbCrLf & _ 
           "line2" & vbCrLf & _ 
           "line3" & vbCrLf & _ 
           "line4" 
    Dim allLines() As String = Microsoft.VisualBasic.Strings.Split(testString, vbCrLf) 
    Dim strConverter As New System.Text.StringBuilder 
    For Each line As String In allLines 
     strConverter.Append("""" & line & """").Append(" & _").Append(vbCrLf) 
    Next 
    If allLines.Length > 0 Then strConverter.Length -= (" & _" & vbCrLf).Length 
    Dim convertedString As String = strConverter.ToString 
相關問題