gpt4 book ai didi

c# - .NET 从文本框填充 StreamReader

转载 作者:太空宇宙 更新时间:2023-11-03 17:37:06 26 4
gpt4 key购买 nike

我想在 streamReader 中解析用户输入。我的代码是:

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(':'));
}
}

我收到这个错误:

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

最佳答案

使用StringReader . TextReader是一个抽象类。您不能创建它的实例。

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

关于c# - .NET 从文本框填充 StreamReader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1222562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com