?
Solved

Put string in an ArrayList...

Posted on 2007-11-28
6
Medium Priority
?
193 Views
Last Modified: 2010-04-15
Hi,
I need to put values from string in an ArrayList.
The string is like that : "1,3,5,7,11"  or : "5,8"  or : "2,3,12"........
I need to put only the numbers in ArrayList.
Thanks
0
Comment
Question by:udir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20364990
the Split() function of C#'s string class does already return an array:
yourtring.Split(',');
0
 
LVL 7

Accepted Solution

by:
Chandan_Gowda earned 2000 total points
ID: 20365037

 // string seperated by colons ','
    string info = "1,2,3,4";
    string[] arInfo = new string[4]; 
 // define which character is seperating fields
    char[] splitter  = {','};         
    arInfo = info.Split(splitter);
    for(int x = 0; x < arInfo.Length; x++)
    {
        //u r logic
    }

Open in new window

0
 
LVL 1

Author Comment

by:udir
ID: 20365098
Chandan_Gowda, Thanks a lot  :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:evilrix
ID: 20365136
It might be worth considering using a StringCollection: -

http://msdn2.microsoft.com/EN-US/library/system.collections.specialized.stringcollection.aspx

    class Program
    {
        static void Main(string[] args)
        {
            string s = "1,2,3,4,5,6,7";
            StringCollection sc = new StringCollection();
            sc.AddRange(s.Split(','));

            ArrayList al = new ArrayList();
            al.AddRange(sc);
        }
    }
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20365158
BTW: The first answer you get isn't always the best solution! You might want to consider leaving a Q open a little longer in future to see if you get a better one.

NB. I am not implying my solution is any better that those already offered, it is just an observation for you to consider.
0
 
LVL 1

Author Comment

by:udir
ID: 20365175
I will take ur advice,
thanks...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question