Q
quincy
I need help. Please bear with this.
I have a program. It takes in files that are delimited.
The delimiters are declared in the file by looking at
fixed positions in the file (If you work with ANSI x12
files, you know what I mean). This normally isn't a
problem, but I'm getting a file that is using some odd
characters as delimiters.
Specifically, a Hex 'BA' is declared as a delimiter. I
read the file into memory using this...
=================================================
fs = New FileStream(InFile, System.IO.FileMode.Open,
System.IO.FileAccess.Read)
sr = New StreamReader(fs, System.Text.Encoding.UTF7)
InputString = sr.ReadToEnd
=================================================
At this point I close the file. In the string, I remove
any carriage control and line feed characters.
Then I write the string to a new file with this.
=================================================
fs2 = New FileStream(OutFile, System.IO.FileMode.Create,
System.IO.FileAccess.Write, IO.FileShare.Write)
sw = New StreamWriter(fs2, System.Text.Encoding.ASCII)
sw.Write(sANSIString)
=================================================
NOTE :Initially, I don't think my stream writer specified
encoding.
Anyway here is the problem....
The resulting file ends up with a different value in the
places where the hex 'BA' used to be. I've played with
various combinations of encoding, for both reading and
writing, and I'm not able to
maintain the character. I need to maintain this!
In one case, the single-byte hex 'BA' is actually
replaced with two bytes, but everything else in the file
is as it should be. In another case, the character is
a "?". I don't remember what happens in other
situations, but in no case is the hex 'BA' maintained.
I don't really understand encoding, so that is only
compounding my frustration and confusion.
Any help is greatly appreciated. I could supply more
details, if necessary.
QM.
I have a program. It takes in files that are delimited.
The delimiters are declared in the file by looking at
fixed positions in the file (If you work with ANSI x12
files, you know what I mean). This normally isn't a
problem, but I'm getting a file that is using some odd
characters as delimiters.
Specifically, a Hex 'BA' is declared as a delimiter. I
read the file into memory using this...
=================================================
fs = New FileStream(InFile, System.IO.FileMode.Open,
System.IO.FileAccess.Read)
sr = New StreamReader(fs, System.Text.Encoding.UTF7)
InputString = sr.ReadToEnd
=================================================
At this point I close the file. In the string, I remove
any carriage control and line feed characters.
Then I write the string to a new file with this.
=================================================
fs2 = New FileStream(OutFile, System.IO.FileMode.Create,
System.IO.FileAccess.Write, IO.FileShare.Write)
sw = New StreamWriter(fs2, System.Text.Encoding.ASCII)
sw.Write(sANSIString)
=================================================
NOTE :Initially, I don't think my stream writer specified
encoding.
Anyway here is the problem....
The resulting file ends up with a different value in the
places where the hex 'BA' used to be. I've played with
various combinations of encoding, for both reading and
writing, and I'm not able to
maintain the character. I need to maintain this!
In one case, the single-byte hex 'BA' is actually
replaced with two bytes, but everything else in the file
is as it should be. In another case, the character is
a "?". I don't remember what happens in other
situations, but in no case is the hex 'BA' maintained.
I don't really understand encoding, so that is only
compounding my frustration and confusion.
Any help is greatly appreciated. I could supply more
details, if necessary.
QM.