Is there any tool for converting multiline text for Visual Studio 2008/2005?

Is there any tool that converts multiline text to a compatible multiline string for Visual Studio 2008/2005?

For instance:

line1 line2 line3 line4 

It should become:

 "line1" & _ "line2" & _ "line3" & _ "line4" 
+4
source share
3 answers

This tool definitely falls into the do-it-yourself category. Launch the new Windows Forms application. Paste the code shown below. Place a shortcut on the program on the desktop. To use it, drag the file from Explorer to the form. Go 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 best mousetrap is to add a file as a resource instead of hard-coding text.

+2
source

Is this what you are 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 
+1
source

A VS macro to insert long text as a string seems like the perfect solution.

0
source

Source: https://habr.com/ru/post/1310777/


All Articles