PC Review


Reply
Thread Tools Rate Thread

concatanate string and byte array

 
 
Peted
Guest
Posts: n/a
 
      3rd May 2007
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
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd May 2007
On May 3, 2:35 pm, Peted wrote:
> 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

 
Reply With Quote
 
Peted
Guest
Posts: n/a
 
      3rd May 2007
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







On 3 May 2007 06:40:56 -0700, "Jon Skeet [C# MVP]" <(E-Mail Removed)>
wrote:

>On May 3, 2:35 pm, Peted wrote:
>> 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


 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      3rd May 2007
Peted wrote:
> 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(); });

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Byte array to string =?Utf-8?B?cGt1bWFy?= Microsoft C# .NET 3 2nd Aug 2005 06:54 AM
byte array to string realgeek@gmail.com Microsoft C# .NET 6 31st Jul 2005 08:48 PM
Re: Byte Array to Printable String to Byte Array Jon Skeet [C# MVP] Microsoft Dot NET 0 4th Aug 2004 01:53 PM
Byte Array to string Jon Microsoft Dot NET 1 26th Nov 2003 12:10 PM
string >> byte array >> string representation >> byte array >> string !! David Bargna Microsoft VB .NET 4 6th Oct 2003 04:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.