How to put special character in each line in textbox vb.net

i have made a application it run cmd commands and read all value in cmd and write it in textbox. it works very well, but i want to add special character in front of each line in the textbox, here is my code :

Imports System.IO

Public Class Form1

    Private strResults As String
    Private Delegate Sub delRefresh()
    Private ShowText As New delRefresh(AddressOf DisplayText)

    Private Sub OverrideCMD()

        Dim prcDOS As New Process
        Dim siDOS As New ProcessStartInfo

        siDOS.FileName = "cmd"

        siDOS.UseShellExecute = False
        siDOS.CreateNoWindow = True
        siDOS.RedirectStandardInput = True
        siDOS.RedirectStandardOutput = True

        prcDOS.StartInfo = siDOS
        prcDOS.Start()

        Dim srInput As StreamWriter = prcDOS.StandardInput
        Dim srOutput As StreamReader = prcDOS.StandardOutput

        srInput.WriteLine(txtCommand.Text)

        srInput.WriteLine("exit")

        strResults = srOutput.ReadToEnd

        srInput.Close()
        srOutput.Close()

        Invoke(ShowText)

    End Sub

    Private Sub DisplayText()
        ' show output to textbox
        txtResults.Text = strResults

    End Sub

    ' textbox where you place cmd commands to execute and then press enter
    Private Sub txtCommand_KeyDown(sender As Object, e As KeyEventArgs) Handles txtCommand.KeyDown
        If e.KeyCode = Keys.Enter Then
                Dim tOverride As New Threading.Thread(AddressOf OverrideCMD)
                tOverride.Start()
        End If
    End Sub
End Class

the result :
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

how to convert the reult text into this :
without ( )

( >> ) Microsoft Windows [Version 6.1.7601]
( >> ) Copyright (c) 2009 Microsoft Corporation. All rights reserved.

help me with fixing the code.. thanks master..

1 answer

  • answered 2018-04-17 05:31 dpant

    By watching strResults you can see lines are separated by the vbCrLf character.

    So you can change:

    strResults = srOutput.ReadToEnd
    

    to the following:

    strResults = vbCrLf + srOutput.ReadToEnd
    strResults = strResults.Replace(vbCrLf, vbCrLf + ">> ")