tags:

views:

260

answers:

1

I want to parse user input in a streamReader. My code is:

string  txt = txtin.text ; //<~~ txtin is something like root:x:1:1....

using (TextReader reader = new TextReader( txt))
{
    string line = "";
    while ((line = reader.ReadLine()) != null)
    {
        string userName = line.Substring(0, line.IndexOf(':'));
    }
}

I get this error:

Cannot create an instance of the abstract class or interface 'System.IO.TextReader'

+9  A: 

Use StringReader. TextReader is an abstract class. You can't create instances of it.

using (TextReader reader = new StringReader(txt))
{
  //...
}
bruno conde