简体   繁体   English

我无法在列表框中输入正确的字符串值

[英]I can't input the right value for string in a list box

Hi I am currently working on a project in my algorithm class. 嗨,我目前正在算法类中的一个项目上工作。 It is a database which searches a list of names for some other names that contains the same letters etc. Whenever a certain radio button becomes checked, the program is supposed to add some names. 它是一个数据库,它在名称列表中搜索包含相同字母等的其他名称。每当选中某个单选按钮时,程序都应添加一些名称。 The program does it well, but instead of putting the names like shown lower, it puts it in one line. 该程序可以很好地完成它,但是与其将显示的名称放在下面,不如将其放在一行中。

It is supposed to look like this but instead it's in one line. 它应该看起来像这样,但是它是一行的。

WILLIAM 威廉

THOMAS THOMAS

FELIX FELIX

LIAM 利亚姆

Here's the text lines (the most important ones) 这是文字行(最重要的)

    {
        lstPrénoms.Items.Clear();
        lstPrénoms.Items.Add("WILLIAM\r\nTHOMAS\r\nFELIX\r\nLIAM\r\n");
    }

Could anyone tell me what's wrong with my text? 谁能告诉我我的文字有什么问题吗?

You can use String.Split to split up your string to multiple lines like this: 您可以使用String.Split将您的字符串分成多行,如下所示:

string s = "WILLIAM\r\nTHOMAS\r\nFELIX\r\nLIAM\r\n";
foreach (string st in s.Split('\r', '\n'))
  listBox1.Items.Add(st);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM