Click here to Skip to main content
11,641,668 members (61,317 online)
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 6: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 Mika Wendelius 260
1 DamithSL 248
2 Afzaal Ahmad Zeeshan 129
3 OriginalGriff 120
4 Sergey Alexandrovich Kryukov 80
0 Mika Wendelius 460
1 OriginalGriff 265
2 DamithSL 258
3 CPallini 169
4 Afzaal Ahmad Zeeshan 149


Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 23 Aug 2012
Copyright © CodeProject, 1999-2015
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