Got a couple of questions on streamreader/filestream. For reference, Im using vb.net ent arch 2003.
1. Im on a US based windows 2000 install. I have a text file that I want to read. The text file could contain asian characters but should contain primarily ascii characters. I think Im saying that right. Anyway, can I use....
... to read the file and still keep the asian characters intact? The part thats reading it is...
... where sBuild is a stringbuilder and bHold is a byte array. And yes, I did steal this stuff from the vbextreme example.
2. Is there a speedy way to break up the text into lines? From vbextreme the fella said ReadLine was slow so Im using ReadBlock but then I still need to split the read text into lines and then parse it for certain text. Should I use ReadLine in this case or go for Splitting the text and then looping through it?
Update:
I decided to change over to ReadLine since the routine Im using is a custom INI file reader and I could shortcircuit it when I hit the value. Testing the VB.Net code against the original VB6 could of mine, it seems the VB.Net code is a little over twice as slow. Return a value in vb6 takes about 0.00105153 seconds while VB.Net return the same value in 0.002876901 seconds. The code is the same except Im using...
.... in VB.Net (along with ReadLine) rather than the VB6 Open For Input As/Line Input method.
Is this normal or should I be doing something else in vb.net?
1. Im on a US based windows 2000 install. I have a text file that I want to read. The text file could contain asian characters but should contain primarily ascii characters. I think Im saying that right. Anyway, can I use....
Code:
Dim sr As StreamReader = New StreamReader(New FileStream(inFile, FileMode.Open), Encoding.Default, False, 4096)
... to read the file and still keep the asian characters intact? The part thats reading it is...
Code:
Do While sr.ReadBlock(cBuffer, 0, cBuffer.Length - 1) > 0
bHold = Encoding.Default.GetBytes(cBuffer)
sBuild.Append(Encoding.Default.GetString(bHold))
Loop
... where sBuild is a stringbuilder and bHold is a byte array. And yes, I did steal this stuff from the vbextreme example.
2. Is there a speedy way to break up the text into lines? From vbextreme the fella said ReadLine was slow so Im using ReadBlock but then I still need to split the read text into lines and then parse it for certain text. Should I use ReadLine in this case or go for Splitting the text and then looping through it?
Update:
I decided to change over to ReadLine since the routine Im using is a custom INI file reader and I could shortcircuit it when I hit the value. Testing the VB.Net code against the original VB6 could of mine, it seems the VB.Net code is a little over twice as slow. Return a value in vb6 takes about 0.00105153 seconds while VB.Net return the same value in 0.002876901 seconds. The code is the same except Im using...
Code:
Dim sr As StreamReader = New StreamReader(New FileStream(inFile, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.Default)
.... in VB.Net (along with ReadLine) rather than the VB6 Open For Input As/Line Input method.
Is this normal or should I be doing something else in vb.net?
Last edited by a moderator: