Solved

Problem with String split & foreach loop

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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