473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

hi,string combination again

hi,
I want to implement a function that prints all possible combinations of a
characters in a string,eg. input "123"into a textbox,
add "1","2","3","12","13","23","123",to a listbox,Or "ab" into a textbox,add
"a","b","ab"in a listbox,
but two combinations that differ only in ordering of their characters are
the same combination. in other words "12" is the same as "21",
i want to know hao to implement by c#,
thanx
Nov 15 '05 #1
1 4128
this little app should do the trick.....i reckon it could be optimized, but
it works....

private void button1_Click(object sender, System.EventArgs e)
{

string word = "";

string anagram = textBox1.Text.ToString();

int size = 0;

int leng = anagram.Length;

listBox1.Items.Clear();

for (int i = 1; i <= leng; i++)

{

word = "";

size = i;

for (int j = 0 ; j < leng; j++)

{

word ="";

word += anagram[j];
if (word.Length == size)

{

listBox1.Items.Add(word);

word = "";

}

else

{

recurr_search_next_letter(word, size,j, leng, anagram);

}
}


}

}

private void recurr_search_next_letter(string word, int size, int teller,
int lengt, string anagram)

{

teller ++;

for (int j = teller; j < lengt ; j++)

{

word += anagram[j];
if (word.Length == size)

{

listBox1.Items.Add(word);

word = word.Substring(0, size-1);

}

else

{

recurr_search_next_letter(word, size,j, lengt, anagram);

word = word.Substring(0, word.Length-1);

}

}

word = "";

}

Hope this works for u,

Bart.

"AsuWoo" <wu*****@msn.com> schreef in bericht
news:#d**************@TK2MSFTNGP10.phx.gbl...
hi,
I want to implement a function that prints all possible combinations of a
characters in a string,eg. input "123"into a textbox,
add "1","2","3","12","13","23","123",to a listbox,Or "ab" into a textbox,add "a","b","ab"in a listbox,
but two combinations that differ only in ordering of their characters are
the same combination. in other words "12" is the same as "21",
i want to know hao to implement by c#,
thanx

Nov 15 '05 #2

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

Similar topics

3
by: gdogg1587 | last post by:
Greetings. I'm working on a program that will "descramble" words. Think of a word scramble game where there is a list of characters, and several blank spaces to denote the word(s) that you are...
7
by: BlueDragon | last post by:
I don't know enough math to demonstrate that any numerical operation with a null should yield a null; although I would guess that it's true. I just don't buy it, however, when dealing with strings...
3
by: AsuWoo | last post by:
hi, I want to implement a function that prints all possible combinations of a characters in a string,eg. input "123"into a textbox, add "1","2","3","12","13","23","123",to a listbox,Or "ab" into a...
4
by: EpicOfChaos | last post by:
Hey guys, Anyone have any code, or psuedo code that would make the following scenerieo? Strings A, B, C Create as many combinations of the 3 strings so long as the length of the entire new...
20
by: sophia | last post by:
Dear all, The following is the program which i have done to find all the combination of letters in the string "hello" #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 5
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.