Got a couple of questions on streamreader/filestream. For reference, I'm using vb.net ent arch 2003.
1. I'm 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 I'm saying that right. Anyway, can I use....
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 that's reading it is...
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 I'm 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 Split'ting the text and then looping through it?
Update:
I decided to change over to ReadLine since the routine I'm 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 I'm using...
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?