Solved

Problem with String split & foreach loop

Posted on 2007-11-21
4
224 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 125 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

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

18 Experts available now in Live!

Get 1:1 Help Now