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

Convert to an Array

How would I convert this string to an Array?
"243, 567, 324, 345"
Where each number becomes a new element in that Array.
Thanks
Nov 22 '05 #1
3 1408
I'm not sure if you want a string array or an integer array but this should
help:

using System.Text.RegularExpressions;
....

Regex rx = new Regex(", ");
string[] myarray = rx.Split("243, 567, 324, 345"); // creates a string array
containing each number

foreach (string s in myarray)
{
// show the string version of this array item
MessageBox.Show("'" + s + "'");

// Convert it to an integer if you like
int myinteger = Int32.Parse(s);
// add the integer to an array here if you like...
}
ShaneB

"Tome73" <To****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
How would I convert this string to an Array?
"243, 567, 324, 345"
Where each number becomes a new element in that Array.
Thanks

Nov 22 '05 #2
For a simple split like this one, you can easily use the Split function
of the String class. Check your online help for examples.

hth, Philipp

Tome73 wrote:
How would I convert this string to an Array?
"243, 567, 324, 345"
Where each number becomes a new element in that Array.
Thanks

Nov 22 '05 #3
The reason I didn't mention string.split is because it won't work as
expected in his case. In the original poster's question, the string he
provided contained a space after each comma. That means the code would have
to look like this:

string s = "243, 567, 324, 345";
string[] myarray = s.Split(new char[]{',' , " "});

As a result, myarray will contains 8 items...because string.split split the
array on each occurance of each character.

Regex.Split() will split it properly and accepts a string input as well.

ShaneB
"Philipp Sumi" <sp*******@thisdomaindoesntexist.org> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
For a simple split like this one, you can easily use the Split function of
the String class. Check your online help for examples.

hth, Philipp

Tome73 wrote:
How would I convert this string to an Array?
"243, 567, 324, 345"
Where each number becomes a new element in that Array. Thanks

Nov 22 '05 #4

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

Similar topics

5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
4
by: Tamir Khason | last post by:
How can I convert (elegant way) Collection to Array without looping and new instances. E.G: I want to add elements of one menu to other, so secondMenu.MenuItems.AddRange(firstMenu.MenuItems);...
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...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
5
by: Peter Nofelt | last post by:
Hi all, My scenario is as follows: * Receive a base 1 array (index starts at 1 instead of 0) of data from a COM component . * Need to pass this array to a .net component that requires its...
5
by: Koolrans | last post by:
Hi All, Don't know if this is covered somewhere else. Could not find it. I have a problem for which I need a solution. I have an array of char chr. I want to convert this to an array of...
2
by: =?Utf-8?B?YW1pcg==?= | last post by:
I am trying to convert a Dictionary into an array so that I can compare values and compare keys individually. I am looking for a solution like array i.e array of array.
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.