How to 'textualize' a buffer

  • Thread starter Thread starter Udi
  • Start date Start date
U

Udi

Hi All,
I'm looking for a way to convert a buffer into text (represent buffer
as text).
The text is read by a parser that needs to cut it at a special
character that is not part of the buffer (E.g.end of line).
(I think this is similar to the method used to 'textualize' binary
data in HTML (to display special characters?) )

For exapmle:
A parser parses the following command line to invoke the function
"Foo" with the relevant parameter
(Command line is all text) :
"Foo(xxx)\n"

Now, I need to receive the same command line with the argument
represented in binary and not in text, and still be able to parse it.

Is there a .Net Class that knows to represent binary in a text format?
Thanks,
Udi.
 
Hi All,
I'm looking for a way to convert a buffer into text (represent buffer
as text).
The text is read by a parser that needs to cut it at a special
character that is not part of the buffer (E.g.end of line).
(I think this is similar to the method used to 'textualize' binary
data in HTML (to display special characters?) )

For exapmle:
A parser parses the following command line to invoke the function
"Foo" with the relevant parameter
(Command line is all text) :
"Foo(xxx)\n"

Now, I need to receive the same command line with the argument
represented in binary and not in text, and still be able to parse it.

Is there a .Net Class that knows to represent binary in a text format?
Thanks,
Udi.

Would this help?

//First working on a real string
byte[] b;
string s3;
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();
b = en.GetBytes("This is a test2\n".ToCharArray());
s3 = en.GetString(b);
Console.WriteLine(s3);

//now working on non printables.
b = new byte[] {1,2,3,4,5,6,7,255,9,10};
s3 = en.GetString(b);
Console.WriteLine(s3);
 
Hi All,
I'm looking for a way to convert a buffer into text (represent buffer
as text).
The text is read by a parser that needs to cut it at a special
character that is not part of the buffer (E.g.end of line).
(I think this is similar to the method used to 'textualize' binary
data in HTML (to display special characters?) )
For exapmle:
A parser parses the following command line to invoke the function
"Foo" with the relevant parameter
(Command line is all text) :
"Foo(xxx)\n"
Now, I need to receive the same command line with the argument
represented in binary and not in text, and still be able to parse it.
Is there a .Net Class that knows to represent binary in a text format?
Thanks,
Udi.

Would this help?

//First working on a real string
byte[] b;
string s3;
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();
b = en.GetBytes("This is a test2\n".ToCharArray());
s3 = en.GetString(b);
Console.WriteLine(s3);

//now working on non printables.
b = new byte[] {1,2,3,4,5,6,7,255,9,10};
s3 = en.GetString(b);
Console.WriteLine(s3);- Hide quoted text -

- Show quoted text -

I don't know.
What would happen if one of the bytes in b has the value of '\n'?
How will this be represented in s3?
I'll test it.
Thanks. :)
 
Hi All,
I'm looking for a way to convert a buffer into text (represent buffer
as text).
The text is read by a parser that needs to cut it at a special
character that is not part of the buffer (E.g.end of line).
(I think this is similar to the method used to 'textualize' binary
data in HTML (to display special characters?) )
For exapmle:
A parser parses the following command line to invoke the function
"Foo" with the relevant parameter
(Command line is all text) :
"Foo(xxx)\n"
Now, I need to receive the same command line with the argument
represented in binary and not in text, and still be able to parse it.
Is there a .Net Class that knows to represent binary in a text format?
Thanks,
Udi.

Would this help?

//First working on a real string
byte[] b;
string s3;
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();
b = en.GetBytes("This is a test2\n".ToCharArray());
s3 = en.GetString(b);
Console.WriteLine(s3);

//now working on non printables.
b = new byte[] {1,2,3,4,5,6,7,255,9,10};
s3 = en.GetString(b);
Console.WriteLine(s3);- Hide quoted text -

- Show quoted text -

No. This won't help. I tested it and the last byte in b (10) is
displayed as '\n', and this is what I need to prevent.
Isn't there any class that would change it to something like '
'
just like it is done done with HTMLs?
 
Would this help?
//First working on a real string
byte[] b;
string s3;
System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();
b = en.GetBytes("This is a test2\n".ToCharArray());
s3 = en.GetString(b);
Console.WriteLine(s3);
//now working on non printables.
b = new byte[] {1,2,3,4,5,6,7,255,9,10};
s3 = en.GetString(b);
Console.WriteLine(s3);- Hide quoted text -
- Show quoted text -

No. This won't help. I tested it and the last byte in b (10) is
displayed as '\n', and this is what I need to prevent.
Isn't there any class that would change it to something like '
'
just like it is done done with HTMLs?- Hide quoted text -

- Show quoted text -

Well \n is 10, can you give a slightly bigger example? I'm sure I'm
missing something.
 
Back
Top