Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 7:56am
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 320
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 184
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 23 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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