首先,到底是什么,我认为没有任何表达,但我问你的专家:
string onUserName = msj.Substring(3);
lstMsjClient.Items.Add(onUserName + "is online now.");
此处onUserName
可以显示在lstMsjClient
内,但"现在在线"无法在lstMsjClient
内显示。
所以不是那么有趣,是什么原因?
那太有趣了。
答案 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?