Click here to Skip to main content
Sign Up to vote bad
good
See more: convert
I'm importing a file from a customer. When I open it up in Ultra Edit is see a hex 85 which shows up as … for the line terminator. I'm trying to convert it to a hex 0A. Anything that windows understands would be fine but 0A is common in many of our other communications. I'm using a .Replace on a StreamReader to replace the value but the output is not what I expect.
 
Replacing "\u0085" with "\u000a" results in … being replace by � which is represented in the hex as EF BF BD.
 
Replacing "\x85" with "\x0a" has the same results.

Any thoughts about what I'm doing wrong? Help is greatly appreciated!
 
// File = Path of original file
String file = File;

// Archive = Path where new file is to be placed
String archive = Archive

FileInfo fi = new FileInfo(file);
String name = fi.Name;

StreamReader sr = new StreamReader(file);
StreamWriter sw = new StreamWriter(archive + name);
 
// Both lines below result in a hex EF BF BD which shows up as … in the text
// String input = sr.ReadToEnd().Replace("\x85", "\x0a");
String input = sr.ReadToEnd().Replace("\u0085", "\u000a");
 
sw.Write(input);
sr.Close();
sw.Close();
Posted 29 Jan '10 - 6:56


2 solutions

Member 3551437 wrote:
// Both lines below result in a hex EF BF BD which shows up as … in the text

 
EF BF BD is the signature of a UTF-8 (MBCS) byte stream. You may find it easier to read the file into memory and then do the replacements by searching for the Unicode '\u0085' characters manually.
  Permalink  
It should be:
String input = sr.ReadToEnd().Replace("\uFFFD", "\x0A");
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 218
1 Ron Beyer 215
2 Aarti Meswania 190
3 Rohan Leuva 178
4 Mahesh Bailwal 160
0 Sergey Alexandrovich Kryukov 8,553
1 OriginalGriff 6,899
2 CPallini 3,648
3 Rohan Leuva 2,963
4 Maciej Los 2,308


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 23 Aug 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid