-1

I want when I read txt file and add in ListBox1.items, add this text http://prntscr.com/on12e0 correct text §eUltra §8[§716x§8].zip not like this http://prntscr.com/on11kv

My code

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    My.Computer.FileSystem.CopyFile(
    appDataFolder & "\.minecraft\logs\latest.log",
    appDataFolder & "\.minecraft\logs\latestc.log")

    Using reader As New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")


        While Not reader.EndOfStream
            Dim line As String = reader.ReadLine()
            If line.Contains(" Reloading ResourceManager: Default,") Then
                Dim lastpart As String = line.Substring(line.LastIndexOf(", ") + 1)

                ListBox1.Items.Add(lastpart)
            End If
        End While
    End Using
    My.Computer.FileSystem.DeleteFile(appDataFolder & "\.minecraft\logs\latestc.log")
End Sub
HereGoes
  • 1,302
  • 1
  • 9
  • 14
  • The paragraph character is not shown properly. Open the file `latestc.log` in Visual Studio in binary mode and take a look at hex code of the paragraph-character. What do you see there ? What is the encoding of the file (UTF-8, UTF-16 ..) ? – Aedvald Tseh Aug 01 '19 at 16:49
  • Almost the same as your previous question: [Read txt and add in richtexbox](https://stackoverflow.com/q/57297064/719186) – LarsTech Aug 01 '19 at 18:26

1 Answers1

0

This question is only different from your first question in that your have substituted a ListBox for a RichTextBox. It seems you got perfectly acceptable answers to your first question. But I will try again.

First get the path to the file. I don't know why you are copying the file so I didn't.

Add Imports System.IO to the top of your file. The you can use the File class methods. File.ReadAllLines returns an array of strings.

Next use Linq to get the items you want. Don't update the user interface on each iteration of a loop. The invisible Linq loop just adds the items to an array. Then you can update the UI once with .AddRange.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "\.minecraft\logs\latest.log")
    Dim lines = File.ReadAllLines(appDataFolder)
    Dim lstItems = (From l In lines
                    Where l.Contains(" Reloading ResourceManager: Default,")
                    Select l.Substring(l.LastIndexOf(", ") + 1)).ToArray
    ListBox1.Items.AddRange(lstItems)
End Sub

If this answer and the previous 2 answer you got don't work, please lets us know why.

Mary
  • 14,926
  • 3
  • 18
  • 27