Thread Object Help

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I want to create a thread object to find any duplicate characters within a
string and get rid of all the duplicate characters within the string, such
as str="abbecdffet". After the thread object runs, the string would become
"abecdfet"

Any help with this would be appreciated.
Thank-you,
Dave
 
Dave said:
I want to create a thread object to find any duplicate characters within a
string and get rid of all the duplicate characters within the string, such
as str="abbecdffet". After the thread object runs, the string would become
"abecdfet"

Any help with this would be appreciated.

Well, which part is the problem - creating the thread, or removing the
duplicates? How far have you already got?
 
Here is what I have so far
public class Duplicate
{
string str2 = "";
int counter;
int strLength;
// constructor
public Duplicate ( string str1 )
{
strLength = str1.Length;
while (counter < str1.Length)
if (str1[counter] != str1[counter - 1])
{
str2 = str2 + str1[counter];
counter = counter + 1;
displayLabel.Text = str2System.Convert.ToString(str1[0]);
}//end if
} // end constructor
}// end Duplicate class

// check button click event
private void checkButton_Click(object sender, System.EventArgs e)
{
// string input by user
string str1 = "";
// get text to remove duplicates from user
str1 = textBox.Text;

Thread thread = new Thread( new ThreadStart(Duplicate.ThreadStart));
DuplicateThread.Start();
}//end check button click event
 
Dave said:
Here is what I have so far

Well, other than the duplicate removal being somewhat inefficient (and
you having a couple of member variables which should be local
variables), it looks like you're nearly there.

All you need to do is move the logic out of the constructor and into a
method which you can access from your checkButton_Click method - make
the constructor just take the original string and stash it away for
later processing.

Out of interest, how long are these strings likely to be? Removing the
duplicates should be pretty fast (especially if you get rid of the
repeated string concatenation and use a StringBuilder) - are you sure
you really need another thread?
 
Back
Top