要在C#的文本框中显示的几个字符串 [英] several string to display in a textbox in C#

查看:56
本文介绍了要在C#的文本框中显示的几个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有几个文件读取的字符串.
现在,我必须在具有多行属性的单个文本框中显示它们
下面我给了代码

Hi All,
I have several string which I got from a file read.
Now I have to show them in a single text box which have multi-line properties
below I had given code

string FstArray = splite[0];
                    string SndArray = splite[1];
                    textBox2.Text = FstArray;



在特定的文本框中,只有第三,第四和第七个字符串应该一个接一个地出现(不是同一行)

感谢所有人
Indrajit



only third,fourth and seventh string should come one by one (not same line) in a particular text box

Thanks To All
Indrajit

推荐答案

假定splite是一个String数组,那么这一行应该可以正常工作.
Assuming that splite is a String array, this single line should work fine.
textBox2.Text = String.Join(System.Environment.NewLine, splite)


使用System.Text.StringBuilder并使用System.Environment.NewLine作为分隔符来连接字符串.

请勿在行分隔符中使用"\ n","\ r"或"\ r \ n",这是不可移植的!

Use System.Text.StringBuilder and concatenate the strings using System.Environment.NewLine as a separator.

Do not use "\n", "\r" or "\r\n" for a line separator — this is not portable!

void PopulateTextBox(string[] source, TextBox destination) {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    int count = 0;
    foreach(string line in source) {
        sb.Append(line);
        if (count < source.Length - 1)
             sb.Append(System.Environment.NewLine);
        ++count;
    }
    destination.Text = sb.ToString(); 
}



—SA



—SA


尝试一下.
Try this.
textBox2.Text = FstArray +  Environment.NewLine + FstArray;


这篇关于要在C#的文本框中显示的几个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆