Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with String split & foreach loop

Posted on 2007-11-21
4
Medium Priority
?
234 Views
Last Modified: 2010-04-15
I have a string that is being read in from a file.
application.exe,pathofapplication

what I need to do is only add the app.exe to my arraylist. I am getting a casting error (Unable to cast object of type 'System.String[]' to type 'System.String') on my foreach loop

What do I need to do to fix this?

arrText.Add(sLine.ToString().Split((@",").ToCharArray()));

foreach (string mystring in arrText)
{
}
0
Comment
Question by:NewMom2Brandon
  • 2
4 Comments
 
LVL 7

Expert Comment

by:lucky_james
ID: 20328048
what is type of arrtext?
0
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 20328054
ArrayList arrText = new ArrayList();
0
 
LVL 11

Accepted Solution

by:
DotNetThinker earned 500 total points
ID: 20328236
try this...


arrText.AddRange(sLine.ToString().Split((@",").ToCharArray()));
0
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 20328345
thank you very much..that was it exactly
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

885 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