zimzim
zimzim

Reputation: 83

.NET fill StreamReader from Textbox

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'

Upvotes: 1

Views: 3195

Answers (1)

bruno conde
bruno conde

Reputation: 48255

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

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

Upvotes: 11

Related Questions