ANIS problem

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

When using StreamReader to read a text file I get some strange behavior
(strange only to me I guess ;-).

If file is saved from Notepad as Unicode the StreamReader works fine.
If file is saved as ANSI, the StreamReader don't read nothing.

Why and how to fix?

Here's my code:
==========
Private Function ReadTextFile(ByVal fName As String) As String
Dim filestream As StreamReader
filestream = File.OpenText(fname)
Dim Contents As String
Contents = filestream.ReadToEnd()
filestream.Close()
Return Contents
End Function
==========
 
Nikolay,
Why and how to fix?

Use the StreamReader constructor instead of File.OpenText. Pass in
Encoding.Default to use the system default ANSI codepage. By default
the StreamReader uses UTF-8.



Mattias
 
Thanks Mattias

Mattias Sjogren said:
Nikolay,


Use the StreamReader constructor instead of File.OpenText. Pass in
Encoding.Default to use the system default ANSI codepage. By default
the StreamReader uses UTF-8.



Mattias
 

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