Memorystream

  • Thread starter Thread starter Bob Hollness
  • Start date Start date
B

Bob Hollness

Hi group,

I am trying to decipher MemoryStream. I need to read the contents of a text
file to memory line by line, process each line and the output the line to a
new text file.

However, it is proving a bit painful trying to work out how to do this with
memorystream. Any chance someone could post some sample code or give
pointers?

Thanks.
 
Bob,

For this is the memorystream not build. The memorystream is to make
streaming possible without the need to write it to an extern medium and visa
versa.

You are doing string manipulations (You reed a file, take from a everytime
new starting point until the vbcrlf a string and goes on like that). However
that is as well not the most easy way when you do that in memory with a
complete file.

Doing this in in my opinion most effective way is using the arraylist or
direct.

pseudo with the arraylist

dim ar as new arraylist
Reading etc
ar.add(rdr.readline)

Processing
for i as integer = 0 to arr.length - 1
proces
write
next

However the best way is ofcourse to incorporate all in one reading and
writing of line process using the streamreader and streamwriter

I hope this helps?

Cor
 
Bob,

I forgot, when you have that text allready in memory, you can use the split
with the vbcrlf to make an array of that.

Cor
 
Cor, maybe he did not make himself clear. I understand it as:

he wants to load a text file into memory. Keep it there for a while, then
as he streams it back to file, add/change the information and then write the
line.

Is it better not to use memorystream for this? I am also looking for the
answer to this!!! ;-)
 
Daniel,

It makes no sense to use the memorystream here.

That is for processes where are no other alternatives than streaming, as
encoding for security or encoding to make it another (file) format.

In yours and Bobs case you are doing string manipulations, wherefore are a
lot of better methods.

I hope this clears it a little bit?

Cor
 
Oh ok. I got it now! What can you suggest as an alternative? Mine is with
a text file containing maybe 300 filenames and paths. I want to read them
in. Use them and then output them with a change later.

Thanks
 
Daniel,

When you are sure it are lines than you can either set them in a listbox, or
a texbox (in multiline mode, that changes the behaviour because it takes
real lines) or even better in a listview. In that listbox you read them as
lines and that textbox you can read it as file, while in the listview (which
is probably the best for your problem, think on explorer) you read them and
process them. That listview is slow when you update it, so set the edit mode
to on. (It is in fact than the right pane of explorer, there are a lot of
samples for that)

There it can be changed. When it has not to be on screen set them in an
arraylist of objects (while I would use a datatable, just because that is
for me easy to handle) as I told while reading.
When it is really needed I will make a very small sample, with the datatable
and show that than in a datagrid however it is dead simple.

However when you want a sample, than show first the structure of that file
textfile because I assume it is CSV and that can even in one time using
OleDB.


Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top