"Special" or Non-English characters in Strings

J

John Straumann

Hello all:

Using a console application, I am trying to process a csv file of names that
are stored like this:

flintstone, fred
rubble, barney
flintstone, dino t.
slate,bart,danny

and I need the final output to be a CSV file of the names in order with or
without the middle initial or name thus:

fred,,flintstone
barney,,rubble
dino,t.,flintstone
danny,bart,slate

However there are characters in the file that are non-english, and when I
process the file these characters are getting replaced by blanks. For
example:

Barkóczi Miklós

becomes

Bark�czi, Mikl�s

Can anyone tell me how I can process the file and retain the characters? I
tried Unicode but that did not work...

Thanks in advance for any and all help.

John.
 
M

Martin Honnen

John said:
However there are characters in the file that are non-english, and when
I process the file these characters are getting replaced by blanks. For
example:

Barkóczi Miklós

becomes

Bark�czi, Mikl�s

Can anyone tell me how I can process the file and retain the characters?
I tried Unicode but that did not work...

Ask the author of the file how it is encoded. Then use that encoding to
read the file. For instance if it is UTF-8 encoded then use
new StreamReader("file.txt", Encoding.UTF8)
if it is Windows-1252 encoded then use
new StreamReader("file.txt", Encoding.GetEncoding(1252))
You could also try
new StreamReader("file.txt", Encoding.Default)
 
J

John Straumann

Hi Martin and Jon:

Thank you for your messages. The data was actually sent to me in the body of
an email message, which I then copied into a CSV file. Should I do something
different?

John.
 
M

Martin Honnen

John said:
Thank you for your messages. The data was actually sent to me in the
body of an email message, which I then copied into a CSV file. Should I
do something different?

Well how exactly to you copy into a CSV file? If you do that in a text
editor and then save to CSV with the text editor then make sure you
check the encoding the text editor uses to save and then use that
encoding in your .NET code as shown in my previous post.
 

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