小编zim*_*zim的帖子

C#将字符串放入TextBox

我想在我的TextBox中显示此代码的结果:

       string txtout1 = txtOrgText.Text.Replace(parm, txtTo.Text).ToString();
       txtout = txtout1;
Run Code Online (Sandbox Code Playgroud)

我有一个文本框,txtOrgtext用户输入文本.我想现在把一些文本放到txtout中.我已将txtout设置为ReadOnly和MultiLine.

当我尝试运行我的程序时,我收到以下错误:

Error   1   Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'   C:\Users\xxx\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 45  25  WindowsFormsApplication1
Run Code Online (Sandbox Code Playgroud)

我试过txtout1.ToString(),但没有任何改变.

我也尝试过txtout.Text = txtout1这个错误:

Cross-thread operation not valid: 
Control 'txtout' accessed from a thread other than the thread it was created on.
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,因为我使用线程,没有线程它工作正常.

c#

6
推荐指数
1
解决办法
8万
查看次数

.NET从Textbox填充StreamReader

我想解析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(':'));
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

无法创建抽象类或接口'System.IO.TextReader'的实例

c# string stream

1
推荐指数
1
解决办法
3013
查看次数

解析文件以获取C#中的名称列表

我正在解析我的/etc/passwd文件,看起来像这样:

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
Run Code Online (Sandbox Code Playgroud)

我希望我的程序返回以下内容:

root
bin
daemon
...
sync
Run Code Online (Sandbox Code Playgroud)

我目前的代码是这样的:

Regex expression = new Regex(@"^\w*");
foreach (Match myMatch in expression.Matches(txt))
{
    txtout.Text = myMatch.ToString();    
}
Run Code Online (Sandbox Code Playgroud)

但是,我只是回来root了这段代码.我怎样才能退回每一行?

c#

0
推荐指数
1
解决办法
207
查看次数

标签 统计

c# ×3

stream ×1

string ×1