首先,这到底是什么,我认为没有任何表达,但我问你专家:
string onUserName = msj.Substring(3);
lstMsjClient.Items.Add(onUserName + "is online now.");
此处onUserName
可以在lstMsjClient
中显示,而"is online now"不能在lstMsjClient
中显示。这不是很有趣吗,原因是什么?
如果使用
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."
因为Substring(3)表示索引开始3.
如果想要前3个字符,必须使用Substring(0,3)
试试这个代码
string msj = "OneTwoThree";
string onUserName = msj.Substring(3);
listBox1.Items.Add(onUserName + "is online now.");
Output : "TwoThreeis online now." ok?