?
Solved

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

Posted on 2011-09-28
7
Medium Priority
?
1,247 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
[X]
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
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

770 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