富文本框更新错误..... [英] Rich Text Box updating error.....

查看:84
本文介绍了富文本框更新错误.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在测试一些我写的奇怪的代码.它认为与我更新清除文本框或处理字符串的方式有关

Hi All,

I am testing some code I have written a spotted an oddity. It think its to do with the way I am updating clearing a text box and or handling a string

     for (int i = 0; i <= a; i++)
     {
        if(stringParts[i] !=String.Empty)
rtbData_Back.Text =  rtbData_Back.Text + stringParts[i].Trim() + "," + '\n';
     }


这个想法是rtbDataBack会使用富文本框中返回的数据进行更新,但是其中可以重复一些数据.
以下是示例

LD:0008 = H2207302611100000041072147,
LD:0009 = H10007408095000029002169,
LD:0009 = H10007408095000029002169,
现在,使用.Clear()清除来自此文本框.方法应该是一个问题,我应该使用.Text ="吗?

Glenn


the idea is rtbDataBack gets updated with the returned data from a rich text box however it can have a piece of data repeated in it.
Below is an example

LD:0008=H2207302611100000041072147,
LD:0009=H10007408095000029002169,
LD:0009=H10007408095000029002169,
now the text box this comes from is cleared using the .Clear(); method can this be a problem should I use .Text = "", or not?

Glenn

推荐答案

您确定这是正确的代码吗?尝试在if之后的语句周围加上大括号.您是否也用调试器检查过stringParts,因为可能仅仅是两行相似.

另外,您可能要考虑使用stringbuilder来执行此操作,因为如果添加更多行,您的代码将变得越来越慢.您一遍又一遍地设置文本,这将每次创建一个新的字符串对象,并且需要将带有附加字符串的所有内容复制到该对象中.

Are you sure this is the exact code? Try putting braces around the statement after the if. Have you also checked with stringParts with the debugger because it might just be that there are simply two lines alike.

Also, you might want to consider using a stringbuilder to do this because your code will be getting slower and slower if more lines are added. You set the Text over and over again which will create a new string object each time and needs to copy everything from that with the additional string into that.

if(stringParts[i] !=String.Empty) {
  rtbData_Back.Text =  rtbData_Back.Text + stringParts[i].Trim() + "," + '\n';
}


祝你好运!


Good luck!


这篇关于富文本框更新错误.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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