Click here to Skip to main content
14,207,581 members
Rate this:
 
Please Sign up or sign in to vote.
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

It should be:
String input = sr.ReadToEnd().Replace("\uFFFD", "\x0A");
   
v2

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



Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190612.1 | Last Updated 23 Aug 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100