【问题标题】:Loading string arrays to richtextbox as columns将字符串数组作为列加载到richtextbox
【发布时间】:2015-10-21 04:32:27
【问题描述】:

我有两个字符串数组。其中一个是 1 2 3,另一个是 4 5 6。我想将这些数据作为 1 "\t" 4 "\n" 2 "\t" 5 "\n" 3 "\t 加载到富文本框中” 6. 我该怎么做? 或者,我将第一个字符串数组加载到richTextBox1 中,将第二个字符串数组加载到richTextBox 中。你也可以这样解释。

这是展示我的目的的图片:

https://mega.nz/#!HRhTjawD!Ft4IAbLNrUkzYUgBSWRjvFeu9P_asPhN_MacdgD7x7U

【问题讨论】:

    标签: c# arrays string richtextbox


    【解决方案1】:

    您可以为此使用字符串生成器。您可以遍历数组并附加到 stringbuilder 对象并在富文本框中使用它。

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < array.Length; i++)
    {
        sb.AppendFormat("{0}    {1}", arr1[i], arr2[i]);
        sb.AppendLine();
    }
    richTextBox1.Text = sb.ToString();
    

    【讨论】:

    • 感谢您的回答,但我在 stringarray 中有大量数据(10000 个数字)。因此,当我尝试调试您编写的代码时,程序停止工作。
    • 抛出了“System.OutOfMemoryException”类型的异常。
    • 谢谢。它现在正在工作。但我也想要两个数组之间的制表符空间(“/t”)。
    • 删除 {0} 和 {1} 之间的空格并保留制表符空间。阅读关于 appendformat。
    • 快完成了。我试过 sb.AppendFormat("{0} {1}", column0Array[t],"\t" + column1Array[t]);有一个选项卡空间,但它不起作用。
    猜你喜欢
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 2016-12-01
    • 2013-12-28
    相关资源
    最近更新 更多