473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

concatanate string and byte array

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
May 3 '07 #1
3 2043
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

May 3 '07 #2
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]" <sk***@pobox.com>
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
May 3 '07 #3
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
May 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
11
by: Dan C | last post by:
Is there a routine in c# that will transform a string ie"Hello Mom" into a Byte array. I have found char cTmp = pString.ToCharArray(); But I have not been able to figure out how to convert a...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
2
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
4
by: ThunderMusic | last post by:
Hi, I have to go from Byte() to String, do some processing then reconvert the String to byte() but using ascii format, not unicode. I currently use a stream to write the char()...
25
by: sravishnu | last post by:
Hello, I have written a program to concatanae two strings, and should be returned to the main program. Iam enclosing the code, please give me ur critics. Thanks, main() { char s1,s2;...
5
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.