Solved

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

Posted on 2011-09-28
7
966 Views
Last Modified: 2012-05-12
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
Comment
Question by:berniefitz
  • 4
  • 3
7 Comments
 
LVL 17

Expert Comment

by:Carlos Villegas
Comment Utility
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
 
LVL 1

Author Comment

by:berniefitz
Comment Utility
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
 
LVL 17

Expert Comment

by:Carlos Villegas
Comment Utility
Can you attach a txt file containing the section with witch you are having problems to decode?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:berniefitz
Comment Utility
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
 
LVL 17

Expert Comment

by:Carlos Villegas
Comment Utility
Hello, try with this ANSI encoding (code page 1252), example:
System.IO.StreamReader(myTextFilePath, System.Text.Encoding.GetEncoding(1252))

Open in new window

0
 
LVL 1

Accepted Solution

by:
berniefitz earned 0 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:berniefitz
Comment Utility
I figured out the problem on my own. Only one comment was partially close but still incorrect.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 74
Problem with SqlConnection 5 108
Non-recursive backtracking, using a stack 1 45
Chat Room 1 22
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now