Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I am trying to read a Textfile with 40.000 lines into a listbox

so I am reading each line and add it to the listbox,

but that takes about 15-20 seconds... way to slow :(

 

Isn't there a faster way to do it? Cause I found a routine

that only takes 4-8 seconds but that reads it into a Datagrid

and that's not what I want.

  • *Experts*
Posted

Don't use the ReadLine or ReadToEnd methods of the reader.

Instead, get the Length of stream, then Read() the entire thing into

a Byte array, and then convert it to a string using

System.Text.Encoding.[whatever encoding].GetString().

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

OK, I have this now and it reads it very fast into s(0)

but still adding to the listviewer takes forever.

 

Dim s As Array

Dim w As String

Dim f As String = "C:\newsgroups.txt"

Dim stream_reader As New IO.StreamReader(f)

s = (Split(stream_reader.ReadToEnd, vbCrLf))

stream_reader.Close()

' MsgBox("done") This takes only 1 second and

' all the data is in s(0)

 

Dim a() As String = s(0).Split(Chr(10))

For x = 1 To a.Length - 1

ListView1.Items.Add(a(x))

Next

 

 

What am I missing here?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...