Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-09-28
7
1,071 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
ID: 36753816
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
ID: 36759437
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
ID: 36766287
Can you attach a txt file containing the section with witch you are having problems to decode?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:berniefitz
ID: 36767777
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
ID: 36793370
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
ID: 36889981
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
ID: 36908509
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Directions API to Map URL -C#? 3 37
MailAddress in vb 4 29
Vector, list Questions R 6 31
Code works but breaks when I add one section 4 20
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …

839 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