Hi,
I have a string and set (I not really using a set, it cud be a arraylist or array of string)
I want to have the following results:
{A, B}
If I have any character that does not contain in the in the set then just concat(concatenate)them to the rest but if it is in the set write the string once with the character and once without it
So for:
aAB -----> aAB aA aB a

what is the best way to do this?

thanks

To be aligned I'll illustrate what I got you mean you want to get distinct characters from string into array
Ex.
Input: RAMY MAHROUS
Output: {R A M Y H O U S}
correct?

No;
Input: aABD and set{A,B}

output:"aABD" "aBD" and "aAD" and "aD"
I mean I once ignor the charcter in the set,and once mention it,
and once don't meantion any of them.like("aD")

thanks

I don't get your rule! can you please guide me with more examples to recognize its pattern


Input: aABD and set{A,B}
output:"aABD" "aBD" and "aAD" and "aD"
I mean I once ignor the charcter in the set,and once mention it,
and once don't meantion any of them.like("aD")

ok,
our input string is "aABD",
my set contians two strings "A" and "B",
the characters which are in the set,I mean "A" and "B",cud come or not come in the input string so(like the roles for epsilon in Automata lectures)
the result string are all these strings:
"A" doesn't come:"aBD"
"A" comes:"aABD"
"B" doesn't come:"aAD"
"B" comes:"aABD"(we had this before so we ignor it)
"A" and "B" don't come:"aD"
"A" and "B" both come:"aABD"(we had this)

this is it:)

That's great :) I develop small method do that work you may use Regular Expression but I prefered to write my code...

MessageBox.Show(Zizi("aABD", new string[]{"A", "B"}, 0)); // No A
MessageBox.Show(Zizi("aABD", new string[] { "A", "B" }, 1)); // No B
MessageBox.Show(Zizi("aABD", new string[] { "A", "B" }, 0,1)); //No A nor B
MessageBox.Show(Zizi("aABD", new string[] { "A", "B" }, 2)); //A and B

 private string Zizi(string str, string[] set, params int[] whatToNotCome)
        {
            string output = str;
            for (int i = 0; i < set.Length; i++)
            {
                if (whatToNotCome.Contains(i))
                    output = output.Replace(set[i], null); 
            }
            return output;
        }

Got the idea or I should explain my code...?

commented: Working!!! +9

thanks Ramy Mahrous

would you plz explain the parameters that you passed to the methed,
and explain a bit about Regular Expression .

regards

Zizi, please take a look on the examples above the code...
First Parameter the string, second one the set, and third you tell the method select to not show first\second\etc.. string from the set..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.