PC Review


Reply
Thread Tools Rate Thread

ANIS problem

 
 
Nikolay Petrov
Guest
Posts: n/a
 
      22nd Oct 2004
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
==========




 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      22nd Oct 2004
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Nikolay Petrov
Guest
Posts: n/a
 
      22nd Oct 2004
Thanks Mattias

"Mattias Sjogren" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem after problem after problem - winXP wont start! =?Utf-8?B?TWF2aXJpY2s=?= Windows XP Help 2 23rd Apr 2006 02:55 PM
System Restore Tab still has access problem (multi-disk problem?) srrstr.dll error Dallas Overturf Windows XP Performance 0 12th Mar 2006 12:52 PM
Problems With Adaptec 2400a RAID Card. (rare problem ? ? ? or Common Problem...? ? ?) Starz_Kid Computer Hardware 0 28th Dec 2005 05:36 AM
hibernation problem! problem!, Power Option problem! Farzad Hayati Microsoft Windows 2000 Hardware 2 5th Feb 2004 10:22 PM
hibernation problem! problem!, Power Option problem! Farzad Hayati Microsoft Windows 2000 Advanced Server 2 5th Feb 2004 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:54 AM.