-
Apr 12th, 2020, 09:27 AM
#1
Thread Starter
Hyperactive Member
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
Learning is a never ending subject.
-
Apr 13th, 2020, 06:43 AM
#2
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!
-
Apr 13th, 2020, 06:52 AM
#3
Thread Starter
Hyperactive Member
Re: Split a text file to get selected text
Learning is a never ending subject.
-
Apr 13th, 2020, 06:57 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|