473,836 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StreamReader Encoding ansi problem

Hi,
I've got a problem using StreamReader in VB.NET.
I try to read a txt file that contains extended characters and theese
are removed from the line that is being read.

I've read a lot of articles about ANSI encoding like this
http://support.microsoft.com/default...b;en-us;889835

but System.Text.Enc oding.Default don't work!!

Any ideas??
Thanks, LucaJonny!

Nov 21 '05 #1
11 31740
LucaJonny schrieb:
Hi,
I've got a problem using StreamReader in VB.NET.
I try to read a txt file that contains extended characters and
theese are removed from the line that is being read.

I've read a lot of articles about ANSI encoding like this
http://support.microsoft.com/default...b;en-us;889835

but System.Text.Enc oding.Default don't work!!

Any ideas??
Thanks, LucaJonny!

Are you sure the file is an ANSI encoded text file?
Armin
Nov 21 '05 #2
Try setting the Encoding parameter of your StreamReader to "Default". I
mean, not the "default" which you get if you leave it blank, but the
actual word "Default". If you system default encoding (mine is, for
example, Western European (Windows)) can handle extended characters,
your problem is solved.
At least, that solved it for me.

Cheers,
zdrakec

Nov 21 '05 #3
Ah, sorry, I see you are using "Default". I mean to say, of course,
check your system's default setting to make sure it can handle the
extended character set.

Sorry,

zdrakec

Nov 21 '05 #4
Ah, sorry, I see you are using "Default". I mean to say, of course,
check your system's default setting to make sure it can handle the
extended character set.

Sorry,

zdrakec

Nov 21 '05 #5
I don't understand!
if I open the file with NOTEPAD (in the open file dialog the ANSI
decoding is setting as default) it seem OK!

if I see in the system setting the international and language options,
there isn't an ANSI western Europe encoding, but only an ANSI central
Europe encoding.

this is the problem???
if so, why NOTEPAD (and other editor software) read well the file??
how I install the ANSI western Europe encoding??

Thanks, LucaJonny!!

zdrakec ha scritto:
Ah, sorry, I see you are using "Default". I mean to say, of course,
check your system's default setting to make sure it can handle the
extended character set.

Sorry,

zdrakec


Nov 21 '05 #6
"LucaJonny" <lu********@gma il.com> schrieb
Hi,
I've got a problem using StreamReader in VB.NET.
I try to read a txt file that contains extended characters and
theese are removed from the line that is being read.

I've read a lot of articles about ANSI encoding like this
http://support.microsoft.com/default...b;en-us;889835

but System.Text.Enc oding.Default don't work!!

Any ideas??
Thanks, LucaJonny!

What do you mean with "extended" characters? Which char codes? Can you show
us the code how you read the file? How do you see that there are "removed"
characters?
Armin

Nov 21 '05 #7
as "extended" characters I mean:

ù
°
½

à
this is my code:

Dim srStreamReader As StreamReader
Dim sFile As String = "C:\Temp\MyText .txt"
Dim sFileText As String

srStreamReader = New StreamReader(sF ile, Encoding.Defaul t)
sFileText = srStreamReader. ReadToEnd()
srStreamReader. Close()

Dim swStreamWriter As TextWriter = New StreamWriter(sF ile & ".new")
swStreamWriter. Write(sFileText )
swStreamWriter. Close()

C:\Temp\MyText. txt seem like:

This is my text file.
In Italian "città" means city
The european currency is EURO (€)
.....
......
.......

C:\Temp\MyText. txt.new seem like:

This is my text file.
In Italian "città " means city
The european currency is EURO (â,¬)
.....
......
.......

Thanks


Armin Zingler ha scritto:
"LucaJonny" <lu********@gma il.com> schrieb
Hi,
I've got a problem using StreamReader in VB.NET.
I try to read a txt file that contains extended characters and
theese are removed from the line that is being read.

I've read a lot of articles about ANSI encoding like this
http://support.microsoft.com/default...b;en-us;889835

but System.Text.Enc oding.Default don't work!!

Any ideas??
Thanks, LucaJonny!

What do you mean with "extended" characters? Which char codes? Can you show
us the code how you read the file? How do you see that there are "removed"
characters?


Armin


Nov 21 '05 #8
"LucaJonny" <lu********@gma il.com> schrieb
as "extended" characters I mean:

ù
°
½
?
à
this is my code:

Dim srStreamReader As StreamReader
Dim sFile As String = "C:\Temp\MyText .txt"
Dim sFileText As String

srStreamReader = New StreamReader(sF ile, Encoding.Defaul t)
sFileText = srStreamReader. ReadToEnd()
srStreamReader. Close()

Dim swStreamWriter As TextWriter = New StreamWriter(sF ile & ".new")
swStreamWriter. Write(sFileText )
swStreamWriter. Close()

C:\Temp\MyText. txt seem like:

This is my text file.
In Italian "città" means city
The european currency is EURO (?)
....
.....
......

C:\Temp\MyText. txt.new seem like:

This is my text file.
In Italian "città " means city
The european currency is EURO (â,¬)
....
.....
......

Thanks

You wrote that the file that you *read* does not contain the extended
characters. I still don't see how you check this. If you read sFileText from
the stream and display it in a the debug window or in a messagebox or a
textbox, are the characters there? If they are there, there is no problem.
As you don't speciy the 'Default' encoding when *writing* the file,
'mytext.txt.new ' is UTF-8 encoded.
Armin

Nov 21 '05 #9
Hey Luca:

Try this:

Dim inputString As String = ""
Dim byteArray() As Byte
Dim inputStream As FileStream
inputStream = New FileStream("pat htosomefile", FileMode.Open,
FileAccess.Read )
ReDim byteArray(CInt( inputStream.Len gth) - 1)
inputStream.Rea d(byteArray, 0, CInt(inputStrea m.Length) - 1)
inputStream.Clo se()
Dim x As Integer
For x = LBound(byteArra y) To UBound(byteArra y)
inputString &= Chr(byteArray(x ))
Next 'x

You will find that "inputStrin g" has the characters that StreamReader
disregarded.

Hope this is helpful,
zdrakec

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2786
by: aurora | last post by:
I have long find the Python default encoding of strict ASCII frustrating. For one thing I prefer to get garbage character than an exception. But the biggest issue is Unicode exception often pop up in unexpected places and only when a non-ASCII or unicode character first found its way into the system. Below is an example. The program may runs fine at the beginning. But as soon as an unicode character u'b' is introduced, the program boom...
12
3971
by: Tamir Khason | last post by:
I have Windows Form application recieved data from clipboard and convert its encoding based on some ruls. So doing following: //from source to multiple targets System.Text.Encoding targ1 = Encoding.GetEncoding("Target_1_code_name"); System.Text.Encoding targ2 = Encoding.GetEncoding("Target_2_code_name"); System.Text.Encoding source = Encoding.GetEncoding("Source_code_name"); byte sourceBytes = source.GetBytes(source); byte targ1Bytes =...
0
3326
by: elliott | last post by:
Hello, I'm trying to use a C# IHttpModule to install a Response filter however IIS keeps removing the Content-Encoding header from the response; but all the other headers I set stay intact. So far I have tested my code on IIS 5.1, 6.0 and ASP.NET Development Server/9.0.0.0 all with the same result. Does anyone have any suggestions?
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10573
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7773
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6973
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3102
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.