By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

reading comma separated numbers.

P: n/a
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?

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pesso <no@where.com> wrote:
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[i] = Byte.Parse(numbers[i]);
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

P: n/a

Yes, you are right, but there is a small change in your code.
I marked it inline.
Thanks,

--------------------
| From: Jon Skeet <sk***@pobox.com>
| Subject: Re: reading comma separated numbers.
| Date: Sat, 20 Sep 2003 10:32:36 +0100
| Message-ID: <MP************************@news.microsoft.com>
| References: <fx***********************@bgtnsc04-news.ops.worldnet.att.net>
| 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!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:186257
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| pesso <no@where.com> wrote:
| > 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[i] = Byte.Parse(numbers[i]);
| }
|
| --
| Jon Skeet - <sk***@pobox.com>
| 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.

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.