473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Thread Object Help

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

Nov 16 '05 #1
3 1393
Dave <da*******@msn.com> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dave <da*******@msn.com> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Dave <da*******@msn.com> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: serge calderara | last post by:
Dear all, I have a function that I need to run in a thread due to the fact that it can takes long time to execute according to the amount of data to collect. This function is also populating a...
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
5
by: Alvin Bruney | last post by:
I dispensed some advice and its bugging me that it may not be 100% accurate. Worker threads should not touch main thread objects. Everybody knows that but if you pass a reference to a form object...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
5
by: taylorjonl | last post by:
I am completely baffled. I am writting a daemon application for my work to save me some time. The application works fine at my home but won't work right here at work. Basically I have a...
0
by: puff | last post by:
When interfacing to a COM object, is it possible to pump messages in a thread? I'm working on an application that automates IE and needs to monitor IE events (yes I know about Pamie). I'm able...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
0
by: roni schuetz | last post by:
since a few day's i'm running around the problem that I stocked with a change i need to do. hopefully somebody here can give me a tipp which will be usefull to solve my problem. I'm using a...
4
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.