By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Read Text VB.net vs. VB6 difference

P: n/a
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!!!!
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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()

"DJ" <te**@spanishsaver.com> wrote in message
news:de**************************@posting.google.c om...
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!!!!

Nov 21 '05 #2

P: n/a
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()
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.