Is there any tool that will convert a multiline text, to a compatible multiline string for Visual Studio 2008/2005?
For example:
line1
line2
line3
line4
Should become:
"line1" & _
"line2" & _
"line3" & _
"line4"
Is there any tool that will convert a multiline text, to a compatible multiline string for Visual Studio 2008/2005?
For example:
line1
line2
line3
line4
Should become:
"line1" & _
"line2" & _
"line3" & _
"line4"
Is this what you're looking for?
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
This kind of tool definitely falls in the do-it-yourself category. Start a new Windows Forms application. Paste the code shown below. Put a shortcut to the program on your desktop. To use it, drag a file from Explorer onto the form. Switch to Visual Studio and type 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
The better mousetrap is to add the file as a resource instead of hard-coding the text.
A VS Macro for Pasting Long Text as String seems like perfect solution.