listBox不会在其中显示手动字符串,而是显示' str'值

时间:2015-09-04 15:41:54

标签: c# listbox

首先,到底是什么,我认为没有任何表达,但我问你的专家:

string onUserName = msj.Substring(3);
lstMsjClient.Items.Add(onUserName + "is online now.");

此处onUserName可以显示在lstMsjClient内,但"现在在线"无法在lstMsjClient内显示。 所以不是那么有趣,是什么原因? 那太有趣了。

1 个答案:

答案 0 :(得分:0)

如果您使用

string msj = "One";
string onUserName = msj.Substring(3);
lstMsjClient.Items.Add(onUserName + "is online now.");

//O is 0
//n is 1
//e is 2
//after blank 3. index


Output : "is online now." 

因为子串(3)意味着索引开始3。

如果你想要前3个字符,你必须使用子串(0,3)

试试这段代码

string msj = "OneTwoThree";
string onUserName = msj.Substring(3);
listBox1.Items.Add(onUserName + "is online now.");

Output : "TwoThreeis online now." ok?