Results 1 to 4 of 4

Thread: Split a text file to get selected text

  1. #1

    Thread Starter
    Hyperactive Member Mallard8's Avatar
    Join Date
    Feb 2018
    Location
    Wales
    Posts
    284

    Split a text file to get selected text

    Get just selected text from a text file. Might help some beginners such as myself.
    Thanks to Chris who gave me a start.
    Code:
    Imports System.IO
    Imports System.Text.RegularExpressions
    
    Public Class Form1
    
        Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
            Dim pattern As String = "-\s"  'Match a white-space character followed by a hyphen.
            Dim getText As String  'Set variable 
            getText = My.Computer.FileSystem.ReadAllText("C:\SomeSums\Saved_Results.txt") 'Get the file
            Dim elements() As String = Regex.Split(getText, pattern) 'Place in array split
            Dim j As Integer = 1 'Set variable
    
            TextBox1.Text = getText 'Show text as it is in file
            For i = 0 To elements.Length - 1 'Lenght of Array
                ListBox1.Items.Add(elements(i)) 'Place the split text in listbox
            Next
    
            For i = 1 To elements.Length / 2  'Length of array / 2 
                Me.Controls("Label" & i.ToString).Text = elements(j) 'Show every other line from array
                j += 2  'Increase  to get every second item
            Next
        End Sub
    
    End Class
    Name:  Split-Text.jpg
Views: 835
Size:  25.7 KB
    Learning is a never ending subject.

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Split a text file to get selected text

    If you don't have any questions or issues this would be better in the code bank.
    Please remember next time...elections matter!

  3. #3

    Thread Starter
    Hyperactive Member Mallard8's Avatar
    Join Date
    Feb 2018
    Location
    Wales
    Posts
    284

    Re: Split a text file to get selected text

    It is, isn't it?
    Learning is a never ending subject.

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Split a text file to get selected text

    Yes it is...Monday morning eyes I guess. Sorry
    Please remember next time...elections matter!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width