473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Encoding problem on VB.Net 2005

Hi all,

in my windows application I have to read a text file to a string array. The
file contains a û character (code 251).
On my pc all works fine, but in the production one the û characters
disapperas, the string resulting 1 character shorter.

The code that do the reading is shown here:

Using sr As System.IO.StreamReader = New
System.IO.StreamReader(Me.File.OpenRead, System.Text.Encoding.UTF8)
Dim s As List(Of String)
s = New List(Of String)
Do While Not sr.EndOfStream
s.Add(sr.ReadLine)
Loop
Return s.ToArray
End If
End Using

Why, even if I force the UTF8 decoding, the behavior on different PCs is not
the same?
My app runs on framework 2.0, operating system is windows xp pro in italian
language (in both PCs).
On my pc were installed the italian language pack: I also installed it on
the production one, but never changed.

Someone could help me?

Thank you in advance.
Lorenzo Puglioli
Jan 23 '08 #1
7 4240
On Jan 23, 2:57*am, Lorenzo Puglioli <Lorenzo
Pugli...@discussions.microsoft.comwrote:
Hi all,

in my windows application I have to read a text file to a string array. The
file contains a û character (code 251).
On my pc all works fine, but in the production one the û characters
disapperas, the string resulting 1 character shorter.

The code that do the reading is shown here:

Using sr As System.IO.StreamReader = New
System.IO.StreamReader(Me.File.OpenRead, System.Text.Encoding.UTF8)
* * * * * * * * Dim s As List(Of String)
* * * * * * * * s = New List(Of String)
* * * * * * * * Do While Not sr.EndOfStream
* * * * * * * * * * s.Add(sr.ReadLine)
* * * * * * * * Loop
* * * * * * * * Return s.ToArray
* * * * * * * * End If
* * * * * * End Using

Why, even if I force the UTF8 decoding, the behavior on different PCs is not
the same?
My app runs on framework 2.0, operating system is windows xp pro in italian
language (in both PCs).
On my pc were installed the italian language pack: I also installed it on
the production one, but never changed.

Someone could help me?

Thank you in advance.
Lorenzo Puglioli
Have you tried "System.Text.Encoding.Default" instead of
System.Text.Encoding.UTF8?
Jan 23 '08 #2
I mean Unicode code point 251 (U+00FB), not ASCII 251. Duh.

--
David Streeter
Synchrotech Software
Sydney Australia
"Lorenzo Puglioli" wrote:
Hi all,

in my windows application I have to read a text file to a string array. The
file contains a û character (code 251).
On my pc all works fine, but in the production one the û characters
disapperas, the string resulting 1 character shorter.

The code that do the reading is shown here:

Using sr As System.IO.StreamReader = New
System.IO.StreamReader(Me.File.OpenRead, System.Text.Encoding.UTF8)
Dim s As List(Of String)
s = New List(Of String)
Do While Not sr.EndOfStream
s.Add(sr.ReadLine)
Loop
Return s.ToArray
End If
End Using

Why, even if I force the UTF8 decoding, the behavior on different PCs is not
the same?
My app runs on framework 2.0, operating system is windows xp pro in italian
language (in both PCs).
On my pc were installed the italian language pack: I also installed it on
the production one, but never changed.

Someone could help me?

Thank you in advance.
Lorenzo Puglioli
Jan 23 '08 #3
Lorenzo,

Probably you mean this one

\\\
Dim Str As New StreamReader(FilePath)
Dim arrInput As Byte() = _
System.Text.Encoding.GetEncoding(437).GetBytes(Str .ReadToEnd)
Str.Close()
///

Have a look at my reply to Gino for the rest of your problem.

Cor
Jan 23 '08 #4
Thanks Cor,

I can try using the encoding you suggest (423-MS DOS), but I still can't
understand what happens.
Why, even if I force a specific encoding, I obtain different results on
different PCs?

In addition, consider that: in my first post I didn't say that I don't
really care the (251) character being read, because it is in a part of file
that I ignore. But i read positionally some other character after this, so
the problem is that they result shifted left.

I explain.
By semplicity, I simplified the input file so it is 5 bytes long:
(32)(251)(32)(13)(10)
On my pc, the resulting string will be 3 characters long: a space, a strange
character (that I don't care) and a space again.
On the other pc it will be only 2 characters long: a space and another
space. The second space (and all other subsequent characters, if any), is
shifted left!

UPDATE:
In the meantime, I have made another test: if I try to read the file on a
CHAR array (using the utf8 decoder), this results the same on both PCs. The
difference happens when I write the char array to a string.
For example using:

dim s as new string(chars)

(where chars is the CHAR array)

I obtain the two different results shown above, even if char arrays are
identical.
I think this is due to the framework internal representation of strings.
So, why are them different? Can I control this?
Thank you
Lorenzo

"Cor Ligthert[MVP]" wrote:
Lorenzo,

Probably you mean this one

\\\
Dim Str As New StreamReader(FilePath)
Dim arrInput As Byte() = _
System.Text.Encoding.GetEncoding(437).GetBytes(Str .ReadToEnd)
Str.Close()
///

Have a look at my reply to Gino for the rest of your problem.

Cor
Jan 23 '08 #5
"SurturZ" <su*****@newsgroup.nospamschrieb:
UTF-8 is an encoding scheme so it won't store ASCII 251
There is not even an ASCII 251 because ASCII is a 7-bit encoding ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jan 23 '08 #6
Lorenzo,
I had a same kind of problem as you too some time ago.

(Using the textbox while copying I got not expected results)

I was forgotten that I had set my computer to the Polish Language, after
setting it back, my problem was gone.

Cor

Jan 24 '08 #7
On Jan 24, 8:05*am, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Lorenzo,

I had a same kind of problem as you too some time ago.

(Using the textbox while copying I got not expected results)

I was forgotten that I had set my computer to the Polish Language, after
setting it back, my problem was gone.

Cor
In a thread, i was having difficulty to display and save non-English
chars, setting encoding type to system.text.encoding.default kicked
the problem away. Note that if you're using Notepad, ANSI encoding
type is default and as suggested in my first reply, setting encoding
mode to default may kick your problem away.

Hope this helps.
Jan 24 '08 #8

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

Similar topics

6
by: Börni | last post by:
Hi, The question might sound (and probably is;-) stupid, but why doesnt the follwing code work?? Is there something i dont see? $doc = new DOMDocument('1.0', 'iso-8859-1'); $doc->formatOutput =...
8
by: janeaustine50 | last post by:
Python's InteractiveInterpreter uses the built-in compile function. According to the ref. manual, it doesn't seem to concern about the encoding of the source string. When I hand in an unicode...
3
by: Nelson R. | last post by:
Hi, im using a form to get some input from the user. This form is in a HTML file. When I post the form directly to my email, i receive all fields correctly. Example test.html: <FORM...
5
by: Dadi | last post by:
Hi, My native language is Icelandic and I´m making a web service that returns results that contain many Icelandic characters. This works fine, however, when I return a soap:Fault, the string in...
11
by: utabintarbo | last post by:
Here is my situation: I am trying to programatically access files created on an IBM AIX system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive on a Win32 system. Not confused?...
2
by: lprisr | last post by:
Hi, I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the...
2
by: Alex Maghen | last post by:
I have created the world's simplest Code-Behind ASPX page in VS 2005. I've used all the defaults. But when I go to build and run the page, it comes up in Chinese (or some Asian character set). I've...
1
by: Sin Jeong-hun | last post by:
Even though I don't use Korean in my codes and comments, I often need to insert Korean literals, because the target users are Koreans. Because I have no plan to globalize those programs, I use...
0
by: a | last post by:
hallo also some vb language question here (but from the vb ng no answer) the htm file created by WVD 2005 has an its own encoding by code (vb net) I need to open it inoculate some text...
0
by: teo | last post by:
hallo encoding loss here, i presume situation: Visual Web Developer 2005 creates a new html file with Visual Web Developer 2005 I write some odd chars
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.