Read Text VB.net vs. VB6 difference

D

DJ

ANY HELP FROM THE MASTERS GREATLY APPRECIATED

When reading textfiles with VB.net, some special character text is
deleted that does not happen with VB6 (Please see below)

ORIGINAL TEXT FILE
"This is a sentence with a spe·ci·fic word." (Note the dot separators
(Hex B7) in the word 'specific' which are syllable breaks).

VB.NET APPLICATION CODE
Dim sr As System.IO.StreamReader = System.IO.File.OpenText(Orginial
file Name)
Console.Write(sr.ReadToEnd)
sr.Close()

CONSOLE OUTPUT
(Or file output or Access record write which I have tried with same
results)

"This is a sentence with a specific word."
(Note the dot separators (Hex B7) in the word 'specific' are GONE?)

HELP
If I do the same thing in VB6, the dot separators (Hex B7) in the word
'specific' REMAIN (spe·ci·fic). Something in the VB.net readtoend
method is deleting the Hex B7 characters. I have also tried the
VB.Net readline method with same readtoend method results.

I want to keep the dot separators! Any ideas????? I hope not to have
to read the file a byte at a time :<(

Thank you!!!!
 
R

Russell Jones

The OpenText method opens a file using UTF8 encoding. Use this syntax
instead to set the encoding. You may need to change the encoding based on
what encoding was used to write the file.

Dim sr As New StreamReader(New FileStream("<file path here>",
FileMode.Open), System.Text.Encoding.Default)
Dim s As String = sr.ReadToEnd
sr.Close()
 
D

DJ

Thank you Russell!!!

Your suggestion to open a filestream with encoding argument worked
like a charm!

Thank you for your time and effort.

DJ

NEW CODE

Dim sr As New System.IO.StreamReader(New
System.IO.FileStream(strMyFile", IO.FileMode.Open),
System.Text.Encoding.Default)

Console.Write(sr.ReadToEnd)

sr.Close()
 

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

Top