473,655 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading comma separated numbers.

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
2 3289
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(numb ers[i]);
}

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

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

--------------------
| From: Jon Skeet <sk***@pobox.co m>
| Subject: Re: reading comma separated numbers.
| Date: Sat, 20 Sep 2003 10:32:36 +0100
| Message-ID: <MP************ ************@ne ws.microsoft.co m>
| References: <fx************ ***********@bgt nsc04-news.ops.worldn et.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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: pc2-rdng5-6-cust18.winn.cab le.ntl.com 81.103.153.18
| Lines: 1
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1862 57
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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(numb ers[i]);
| }
|
| --
| Jon Skeet - <sk***@pobox.co m>
| 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3080
by: Craig Keightley | last post by:
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the comparison is to check that if product a who supplies products 1,2,3,4,5 can be used instead of product b who supplies 3,5 as product a already supplies them
1
6684
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal processing. I am having no luck at all finding different routines written in C to read delimited files of any kind. I have a few ideas of how I might go about this but I bet I'm re-inventing the wheel and there already exists some efficient code out...
3
6114
by: starman7 | last post by:
I'm attempting a query that gathers product data for a particular product id. One of the items is designer(s) which can be more than one. The product table has comma separated id's of the designers in the designers table (which has fields like: id, fname, lname). How can my select return the possibly several designers for a product, with the rest of the row data, like price, name, etc.?
1
5922
by: nribeck | last post by:
I have a very simple question, but I am rather inexperienced in C so I can't figure it out. I have a bunch of comma separated files, and each field is in quotation marks. Individual records are separated by carriage returns. I want to be able to to go a given record (a specific line in the file) and the read the data in a specific field in that record into an int or a char depending on whether the entry in that field is a number or text. ...
2
3218
by: Wes Peters | last post by:
Does anyone know of an article that deals with the subject of reading a structured text file using VBA code in Access? Thanks, Wes
17
2818
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that creates a character string containing the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) = F(1) = 1 -, separated by comma. n should be given as an argument to the program. The recursive function should only take one parameter, n, and...
13
3164
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that creates a character string containing the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) = F(1) = 1 -, separated by comma. n should be given as an argument to the program. The recursive function should only take one parameter, n, and...
1
3444
by: Twanne | last post by:
Hi, I've got some code in VBA where I calculate some numbers. Now some of them are large decimal numbers like -6,3216324E03. So in scientific notations. Now I need to add them to a table with an insert query. The query: db.Execute ("INSERT INTO tmpZscore (datum, leeftijd, lengte, ZscoreL, gewicht, ZscoreW, BMI, ZscoreB, IBW) VALUES('" & CStr(dag & "/" & maand & "/" & Jaar) & "','" & test & "','" & CStr(lengte) & "'," & CDbl(scoreL) & ",'"...
3
1892
by: nvrivers | last post by:
I am trying to figure out how to do a query in Access 2000 that will find all records that contain the number 1. The problem is that the particular field I am searching has lists of numbers in it separated by commas. For example, the field may contain the numbers 1,71,38,81. (The field is formatted as a text field) I want to pull up all the records that contain the number 1, but if I search for 1, I also get records that contain 71 or 61 or...
0
8380
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.