[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1395
  • Last Modified:

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.



0
berniefitz
Asked:
berniefitz
  • 4
  • 3
1 Solution
 
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
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Can you attach a txt file containing the section with witch you are having problems to decode?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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:
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
 
berniefitzAuthor Commented:
I figured out the problem on my own. Only one comment was partially close but still incorrect.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now