VB.Net Streamreader

Simon Scott 306 Reputation points
2020-11-30T10:51:17.827+00:00

Good morning all.
I have basic coding skills so please bear with me!
I have created an application which writes a line of text to a file, simple enough. The line itself says xxxxxx | xxxxxx.
Could someone tell how i extract the second part of that line after the pipe?
The intention is to pass this text to a cmd line.
Many thanks
Simon

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,658 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 83,096 Reputation points
    2020-11-30T11:05:16.167+00:00

    You can do something like (test file "E:\Testxxx.txt"):

    Dim sString As String = Nothing
    Using sr As New StreamReader("E:\Testxxx.txt")
        sString = sr.ReadToEnd()
    End Using
    Dim sSubString = sString.Substring(sString.LastIndexOf("|") + 1)
    Console.WriteLine(sSubString)
    
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Simon Scott 306 Reputation points
    2020-11-30T11:06:32.883+00:00

    Thank you very much for your quick reply.

    I shall give that a go and let you know how i get on!

    Kind regards
    Simon

    0 comments No comments

  2. Simon Scott 306 Reputation points
    2020-12-01T08:52:34.58+00:00

    Hi Castorix31,

    That's perfect, that has extracted the information i need :)

    One last bit now, how can i send that text to a CMD line? I need the CMD line to open and run with that text and stay open (so i can check its run ok).

    I have looked online but there are multiple examples but none quite do what i want them to do!

    Thanks so much.
    Simon


  3. Simon Scott 306 Reputation points
    2020-12-01T09:24:13.747+00:00

    No problem Valdom.

    I'll start another thread.

    0 comments No comments