How to display international characters?

G

Guest

I'm loading some names from a file which contains many names, some of which
have some international charcaters like: ö

When I load these names and put them into GUI Labels or DataGrid columns
those characters turn into a question mark, so instead of seeing 'Böhme' I
see 'B?hme'...

any idea why?
 
G

Guest

Actually, I went to double check and it's not the UI controls that are the
problem... the string has got a question mark character as soon as I load
from the file. I read the file like this:

using (StreamReader sr = new StreamReader(file.OpenRead(), Encoding.ASCIi)) {
string line = sr.ReadLine();
// etc ...
}

and right away, I see the question mark in 'line' instead of the right
character

what am I doing wrong?
 
C

Cor Ligthert

Mr Nobody,

The reason is probably that the language or regional settings of your
workstation do not have the codetable wherein that file is written. To
change that in your computer is only a temporaly solution for you.

Better is to find out how that file is written and than read it with the
encoding.
http://msdn.microsoft.com/library/d...ef/html/frlrfsystemtextencodingclasstopic.asp

(When you think nothing works do than not forget to the method
"getencoding").

I hope this helps?

Cor
 
M

Mattias Sjögren

using (StreamReader sr = new StreamReader(file.OpenRead(), Encoding.ASCIi)) { [...]
what am I doing wrong?

You're using the ASCII encoding when reading the file, which doesn't
support these characters. You have to use an encoding that matches how
the file was originally written, most likely Encoding.Default or UTF8.



Mattias
 
G

Guest

OK I tried Encoding.Default and it loaded the characters without a problem,
but then when I tried to write the file using Encoding.Default it put those
question marks in the file (I viewed the file with Word and Excel)

Mattias Sjögren said:
using (StreamReader sr = new StreamReader(file.OpenRead(), Encoding.ASCIi)) { [...]
what am I doing wrong?

You're using the ASCII encoding when reading the file, which doesn't
support these characters. You have to use an encoding that matches how
the file was originally written, most likely Encoding.Default or UTF8.



Mattias
 
K

Kai Brinkmann [MSFT]

Encoding.Default uses the system's current ANSI code page. If a character
cannot be represented using this code page (as seems to be the case here),
you end up with a question mark. To make sure that you can accurately
represent all characters, you should use Encoding.UTF8 or Encoding.Unicode.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


MrNobody said:
OK I tried Encoding.Default and it loaded the characters without a
problem,
but then when I tried to write the file using Encoding.Default it put
those
question marks in the file (I viewed the file with Word and Excel)

Mattias Sjögren said:
using (StreamReader sr = new StreamReader(file.OpenRead(),
Encoding.ASCIi)) { [...]
what am I doing wrong?

You're using the ASCII encoding when reading the file, which doesn't
support these characters. You have to use an encoding that matches how
the file was originally written, most likely Encoding.Default or UTF8.



Mattias
 
G

Guest

Thanks for your reply!

I tried using Unicode, and everytihng just broke (The lines it reads is just
filled with boxes- no recognizeable characters) With UTF8 it loaded the file
but then instead of putting question marks it actually REMOVED the
international characters!
 

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

Top