Click here to Skip to main content
15,899,556 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

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
Posted

1 solution

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.

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

Good luck!
 
Share this answer
 
Comments
glennPattonWork3 20-Feb-12 9:39am    
Thanks! I need luck, good fortune, positive vibes as this needs to be done yesterday!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900