concatanate string and byte array

P

Peted

Is it possible to concatanate a string and a byte array, into a
"string" variable, send it as a string to an ip socket device and have
the bytes, seen as a sequence of bytes, not char or string ?


I have a machine connected to a ip signal routing device. The ip
routing only takes strings as data, but the machine connected, needs a
sequence of 32 bytes for its instruction set.

or is there perhaps a way to do in a string something similar to
\xBE\xEF, but instaed of producing ascii from the hex numbers, encode
them as bytes.

Any ideas appreciated


thanks

Peted
 
J

Jon Skeet [C# MVP]

Is it possible to concatanate a string and a byte array, into a
"string" variable, send it as a string to an ip socket device and have
the bytes, seen as a sequence of bytes, not char or string ?

When data is sent across the network, it is *always* just sent as
bytes. There's nothing else it can be sent as.
I have a machine connected to a ip signal routing device. The ip
routing only takes strings as data, but the machine connected, needs a
sequence of 32 bytes for its instruction set.

It's not clear what layers you're really talking about here. As I say,
as far as the socket is concerned, there's only binary data. If you
have a layer over that which is able to pass arbitrary text data, and
you need to encode some binary data, then Base64 (which a length
prefix of some description) is a good plan.

If that doesn't help, please provide more information.

Jon
 
P

Peted

Hi thanks,

ive just realised the problem seems to be my doing, but i dont know
how to fix it

ive found out that this sequence

EG: "W01RS|\x4E\x31\x0D" (this sends the characters N1<CR>) to the
ip device serial port 1

the above works(ie it does what i want) if i use it as a string
variable and send it that way

ie String cmd = "W01RS|\x4E\x31\x0D";

but if i enter W01RS|\x4E\x31\x0D into a textbox, then send the
Textbox.text value the esc \x stuff does not work. All the \x get
sent as litteral characters without performing the esc functions.

Can anyone tell me how i can make it process the esc after eneter into
textbox, and getting the text value. I need to do this as a testing
application, so a user can manually enter different commands to test
them out

thanks for any help

Peted
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Peted said:
Hi thanks,

ive just realised the problem seems to be my doing, but i dont know
how to fix it

ive found out that this sequence

EG: "W01RS|\x4E\x31\x0D" (this sends the characters N1<CR>) to the
ip device serial port 1

the above works(ie it does what i want) if i use it as a string
variable and send it that way

ie String cmd = "W01RS|\x4E\x31\x0D";

but if i enter W01RS|\x4E\x31\x0D into a textbox, then send the
Textbox.text value the esc \x stuff does not work. All the \x get
sent as litteral characters without performing the esc functions.

Can anyone tell me how i can make it process the esc after eneter into
textbox, and getting the text value. I need to do this as a testing
application, so a user can manually enter different commands to test
them out

thanks for any help

Peted

Use a regular expression to match the escape sequences and use a
delegate in a replace to parse them and convert them into characters.
Example:

string s = Regex.Replace(@"W01RS|\x4E\x31\x0D", @"\\x[\dA-F][\dA-F]",
delegate(Match m) { return
((char)int.Parse(m.Groups[0].Value.Substring(2),
NumberStyles.HexNumber)).ToString(); });
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top