Solved

Put string in an ArrayList...

Posted on 2007-11-28
6
183 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
6 Comments
 
LVL 142

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 500 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now