Insert line separator : Special Chars « Data Type « VB.Net Tutorial






Public Class Tester
    Public Shared Sub Main
        Dim result As New System.Text.StringBuilder
        result.AppendLine("A")
        result.AppendLine("B")
        result.AppendLine("C")
        result.AppendLine("D")
        result.Append("E")

        Dim resultAsString As String = result.ToString()
        Console.WriteLine(resultAsString)

        resultAsString = InsertLine(resultAsString, 3, "(inserted)")
        Console.WriteLine(resultAsString)

 
    End Sub
    Public Shared Function InsertLine(ByVal source As String, _
      ByVal lineNum As Integer, _
      ByVal lineToInsert As String) As String

        Dim lineSet() As String
        Dim atLine As Integer

        lineSet = Split(source, vbNewLine)

        atLine = lineNum
        If (atLine < 0) Then atLine = 0
        If (atLine >= lineSet.Length) Then
            lineSet(lineSet.Length - 1) &= vbNewLine & lineToInsert
        Else
            lineSet(atLine) = _
               lineToInsert & vbNewLine & lineSet(atLine)
        End If

        Return Join(lineSet, vbNewLine)
    End Function

End Class
A
B
C
D
E
A
B
C
(inserted)
D
E








2.15.Special Chars
2.15.1.NewLine sign: vbNewLine, vbLrLf, vbCr, Environment.NewLine, ControlChars.NewLine
2.15.2.vbNewLine
2.15.3.Concatenate vbTab with Integer
2.15.4.Insert line separator