2010-05-24 61 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 
相关问题