EDN Admin
Well-known member
There have a file which contains mixed HEX and ASCII. For example, the first 8 characters of the file are ASCII and following by 16 binary and rest is ASCII.
Here is sample file in opening as HEX mode. <br/>
58 4d 4c 00 00 00 ac 13 00 00 ... 4d 4c ...
I am trying to read file content using filestream into bytes[]. I would like to convert this bytes[] into string and feed in a business logic component. When component complete processing, it returns a string. I have to convert string back to bytes and write
into file.
I am using the following statement but got incorrect result. Could anyone give a light for this issue?
<pre style="font-family:Consolas; background-color:white <span style="color:blue static <span style="color:blue string ConvertToString(<span style="color:blue byte[] input)
{
<span style="color:blue string output = <span style="color:blue string.Empty;
<span style="color:blue return System.Text.<span style="color:#2b91af Encoding.UTF8.GetString(input);
}
<span style="color:blue static <span style="color:blue byte[] ConvertToBytes(<span style="color:blue string input)
{
<span style="color:blue byte[] output = <span style="color:blue null;
<span style="color:blue return System.Text.<span style="color:#2b91af Encoding.UTF8.GetBytes(input);
}
[/code]
View the full article
Here is sample file in opening as HEX mode. <br/>
58 4d 4c 00 00 00 ac 13 00 00 ... 4d 4c ...
I am trying to read file content using filestream into bytes[]. I would like to convert this bytes[] into string and feed in a business logic component. When component complete processing, it returns a string. I have to convert string back to bytes and write
into file.
I am using the following statement but got incorrect result. Could anyone give a light for this issue?
<pre style="font-family:Consolas; background-color:white <span style="color:blue static <span style="color:blue string ConvertToString(<span style="color:blue byte[] input)
{
<span style="color:blue string output = <span style="color:blue string.Empty;
<span style="color:blue return System.Text.<span style="color:#2b91af Encoding.UTF8.GetString(input);
}
<span style="color:blue static <span style="color:blue byte[] ConvertToBytes(<span style="color:blue string input)
{
<span style="color:blue byte[] output = <span style="color:blue null;
<span style="color:blue return System.Text.<span style="color:#2b91af Encoding.UTF8.GetBytes(input);
}
[/code]
View the full article