Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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.
 
Share this answer
 
It should be:
String input = sr.ReadToEnd().Replace("\uFFFD", "\x0A");
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900