reading comma separated numbers.

  • Thread starter Thread starter pesso
  • Start date Start date
P

pesso

I have a string that contains the following:
string s = "130,41,43,178,41,17,6,78,244,35,202,144,115";

They are comma separated byte numbers, and I need to
initialize my byte[] array with them. Looks like I need a loop
or something. What would be the best way to take a
comma separated string to initialize a byte[] array using cs?
 
pesso said:
I have a string that contains the following:
string s = "130,41,43,178,41,17,6,78,244,35,202,144,115";

They are comma separated byte numbers, and I need to
initialize my byte[] array with them. Looks like I need a loop
or something. What would be the best way to take a
comma separated string to initialize a byte[] array using cs?

string[] numbers = s.Split(',');
byte[] bytes = new byte[numbers];
for (int i=0; i < numbers.Length; i++)
{
bytes = Byte.Parse(numbers);
}
 
Yes, you are right, but there is a small change in your code.
I marked it inline.
Thanks,

--------------------
| From: Jon Skeet <[email protected]>
| Subject: Re: reading comma separated numbers.
| Date: Sat, 20 Sep 2003 10:32:36 +0100
| Message-ID: <[email protected]>
| References: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: MicroPlanet Gravity v2.60
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: pc2-rdng5-6-cust18.winn.cable.ntl.com 81.103.153.18
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:186257
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| > I have a string that contains the following:
| > string s = "130,41,43,178,41,17,6,78,244,35,202,144,115";
| >
| > They are comma separated byte numbers, and I need to
| > initialize my byte[] array with them. Looks like I need a loop
| > or something. What would be the best way to take a
| > comma separated string to initialize a byte[] array using cs?
|
| string[] numbers = s.Split(',');
| byte[] bytes = new byte[numbers];
~~~~~~~numbers.Length
| for (int i=0; i < numbers.Length; i++)
| {
| bytes = Byte.Parse(numbers);
| }
|
| --
| Jon Skeet - <[email protected]>
| http://www.pobox.com/~skeet
| If replying to the group, please do not mail me too
|


Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top