StreamReader.ReadLine() into a String UTF-8 Encoding

Hi,

I have a small program where I am trying to read a text file, make some minor updates to some of the fields and then output to a new text file.

I'm having trouble with one field in the data.  When I read the field I get incorrect encoding.  I test the encoding of the file and get that it is UTF8 but this introduces sqaure boxes instead of certain characters when reading the field.  The closest I get is using UTF7 but this removes two plus symbols.

I'm a bit lost, any help would be greatly appreciated.

Thanks, Bernie.



LVL 1
berniefitzAsked:
Who is Participating?
 
berniefitzConnect With a Mentor Author Commented:
Hi there,

Thanks for your help.  I solved the issue.

Basically, I had to read the text in as UTF7 and output as Encoding.GetEncoding(1250)).

Very strange considering if I test the encoding of the file in C# it tells me that it is UTF8.

Thanks for all your help.
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, have you tried setting manually the encoding instead of auto detection?
Example (interpreting Unicode):
System.IO.StreamReader(myTextFilePath, System.Text.Encoding.Unicode)

Open in new window

0
 
berniefitzAuthor Commented:
Yeah. I've tried manually encoding UTF7, UTF8, Unicode and ASCII and none read the string correctly.

The string is ÌSPÇ34*-RÈ_4207478_Ç()4+%*4+$Â'*Î
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Carlos VillegasFull Stack .NET DeveloperCommented:
Can you attach a txt file containing the section with witch you are having problems to decode?
0
 
berniefitzAuthor Commented:
I've attached a file with the text I can't read.  I've blanked other fields with XXX for privacy reasons.

Thanks. TESTFILE.TXT
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, try with this ANSI encoding (code page 1252), example:
System.IO.StreamReader(myTextFilePath, System.Text.Encoding.GetEncoding(1252))

Open in new window

0
 
berniefitzAuthor Commented:
I figured out the problem on my own. Only one comment was partially close but still incorrect.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.