Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file where items on each line are delimited by "|".
I'm reading each line into a List of strings. Then processing each line.
As you can see this is pretty straight forward.
when the compiler see s.Split(delim); it says:
"The best overloaded method match for 'string.Split(parms char[])' has some invalid arguments"
I do not understand why the error exists or how to fix it.
Please assist with a correction of the code below.
Thanks

C#
List<string> TempList = new List<string>();

using (StreamReader r = new StreamReader(Filename))
{
    string line;
    while ((line = r.ReadLine()) != null)
    {
        TempList.Add(line);
    }
}

string delim = "|"
string[] ControlParts;
foreach ( string s in TempList) {
    ControlParts = s.Split(delim);
    _MeditechConnections.Add(ControlParts[0]);
}
Posted
Updated 15-Feb-11 14:04pm
v4

Change
C#
string delim = "|"

to
C#
string delim = '|'

so that you are passing a char not a string.

The versions of Split that take a string parameter require additional parameters.
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 15-Feb-11 21:17pm    
As simple as that, 5.
--SA
MacIntyre 16-Feb-11 10:46am    
This almost worked. what worked was: char delim = '|';
You could always use the String.ToCharArray():
C#
ControlParts = s.Split(delim.ToCharArray());
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Feb-11 21:17pm    
Another way, my 5
--SA
MacIntyre 16-Feb-11 10:47am    
This worked the first time.. Perfect...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900