473,387 Members | 1,530 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,387 software developers and data experts.

breaking up strings

Ben
I have this data I want to send over the network to the server. It is
working fine except I don't know how to break up the buffer on the receiving
side. On the client I am sending "hostname<BREAK>data<EOF>" The server
receives this packet but how would I break it up?

I usually use structs in C for this but how do structures work in VB2005? I
can define
structure mydata
hostname as string
data as string
end structure

but how does the server know where the hostname stops and the data begins?
In C I would do something like
struct mydata {
char hostname[32]
char data[1024]
}

I guess what I am asking how do I specify the length of a string?

Thanks,
Ben
May 27 '06 #1
2 1310
There are two major differences between a C char[] and a .NET string:

:: A C char[] is a value type, while a .NET string is an object. If you
put two strings in a struct, it will just contain two references (fancy
pointers).

:: A C char[] is an array of byte values, while a .NET string contains
an array of (16 bit) unicode characters.

What you are recieving over the network is probably either an array of
bytes or a string.

If it's array of bytes you need to decode it into a string, using an
Encoding object. For instance the Encoding.ASCII.GetString() method.

To split it up, you just use the Split method of the string class to
split the string on the <BREAK> character that you used between the
values. The result is an array of string.

Ben wrote:
I have this data I want to send over the network to the server. It is
working fine except I don't know how to break up the buffer on the receiving
side. On the client I am sending "hostname<BREAK>data<EOF>" The server
receives this packet but how would I break it up?

I usually use structs in C for this but how do structures work in VB2005? I
can define
structure mydata
hostname as string
data as string
end structure

but how does the server know where the hostname stops and the data begins?
In C I would do something like
struct mydata {
char hostname[32]
char data[1024]
}

I guess what I am asking how do I specify the length of a string?

Thanks,
Ben

May 28 '06 #2
Ben
Thank you for excellent explanation. I now understand and have fixed the
problem.

Thanks again,
Ben

"Göran Andersson" <gu***@guffa.com> wrote in message
news:Og****************@TK2MSFTNGP04.phx.gbl...
There are two major differences between a C char[] and a .NET string:

:: A C char[] is a value type, while a .NET string is an object. If you
put two strings in a struct, it will just contain two references (fancy
pointers).

:: A C char[] is an array of byte values, while a .NET string contains an
array of (16 bit) unicode characters.

What you are recieving over the network is probably either an array of
bytes or a string.

If it's array of bytes you need to decode it into a string, using an
Encoding object. For instance the Encoding.ASCII.GetString() method.

To split it up, you just use the Split method of the string class to split
the string on the <BREAK> character that you used between the values. The
result is an array of string.

Ben wrote:
I have this data I want to send over the network to the server. It is
working fine except I don't know how to break up the buffer on the
receiving side. On the client I am sending "hostname<BREAK>data<EOF>"
The server receives this packet but how would I break it up?

I usually use structs in C for this but how do structures work in VB2005?
I can define
structure mydata
hostname as string
data as string
end structure

but how does the server know where the hostname stops and the data
begins? In C I would do something like
struct mydata {
char hostname[32]
char data[1024]
}

I guess what I am asking how do I specify the length of a string?

Thanks,
Ben

May 28 '06 #3

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

Similar topics

27
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody...
22
by: stevenkobes | last post by:
If a word has a hyphen in it, IE will permit a line break at the hyphen, but Firefox/Mozilla won't. Apparently the Firefox behavior is standards-compliant, but it is not what I want. Is there a...
5
by: Michael Yanowitz | last post by:
Hello: I have been searching for an easy solution, and hopefully one has already been written, so I don't want to reinvent the wheel: Suppose I have a string of expressions such as: "((($IP =...
2
by: gitimaya | last post by:
hi, can anyone please help me in breaking up a string in array of strings. The delimeter is a character declared as '\001'. lets say i have a string as char d='\001' xxx'd'yyy'd'aaa i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.