我该如何执行这个逻辑 [英] How can I execute this logic
本文介绍了我该如何执行这个逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
foreach (string text in storedata)
{
txtclients.Text = txtclients.Text + text + "\n";
}
Txtclients是多行文本框的ID
您能否请将逻辑分享为上次执行foreach循环时不希望\ n执行。
我尝试了什么:
请你分享逻辑,因为上次执行foreach循环时不希望\ n执行。
Txtclients is id for multiline Text Box
Could you please share the logic as dont want "\n" to be execute when foreach loop is executing last time.
What I have tried:
Could you please share the logic as dont want "\n" to be execute when foreach loop is executing last time.
推荐答案
如果要替换文本框的全部内容,请尝试以下简单方法:
If you're replacing the entire contents of the textbox, try the simple approach:
txtclients.Text = string.Join("\n", storedata);
在循环之后你可以添加
After the loop you could add
txtclients.Text = txtclients.Text.TrimEnd('\n');
首先,选择语言:
- 代码不是基本的
foreach $的原则c $ c>避免使用计数器因此,在循环中,你不知道你何时在最后一次迭代。
传统的解决方案更像是:
First, choose the language:
- the code is not basic
The principle offoreach
is avoid having a counter thus, in the loop, you don't know when you are in last iteration.
The traditional solution is more like:
txtclients.Text = txtclients.Text + storedata[0];
for (int i=1; i< storedata.count; i++)
{
txtclients.Text = txtclients.Text + "\n" + storedata[i];
}
这篇关于我该如何执行这个逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文