hi,

I have a string that has duplicates like "SbS"I want to replace one the first "S" and the other time,the other "S",so the output for it would be:

"Sb" and "bS"

but as I do it with Replace to just get one result that is :

"b"

what is the ways I cud solve this problem.


regards

Are you getting a user input or is the program supposed to do this?

Please show what you have thought about the Logic or show me your pseudo code

I have a arraylist showing the characters that cud come or not to come in the string,
I have made a post for this on this link but I forgot to talk about the duplicates,
so still my problem remains,
http://www.daniweb.com/forums/thread284139.html

thanks

can you elaborate what you want the result to be.

i.e.

AbbaSAbbast

What should this print?

finito:

AbbaSAbbast

What should this print?

if we assume that the only character existing in the arraylist is just the string
"A"
so the the arraylist is {"A"},the input string is "AbbaSAbbast",
the result would be:

"bbaSAbbast" and
"AbbaSbbast" and
"bbaSbbast" and
"AbbaSAbbast"

if we have a string "SbSA" and the arraylist contains {S,A}
the result shold be:
one of them doesn't come:
"bSA"
"SbA"
"SbS"
two of them doesn't come:
"bA"
"bS"
"Sb"
all of them come
"SbSA"
none of them comes
"b"

I hope that you understand me.

thanks finito.

OK I am more confused now.

This part

two of them doesn't come:
"bA"
"bS"
"Sb"

is where I lost you.

You say 2 of them don't come, I am assuming you receive the input to search which char to remove. In this case is {S,A}.

So if boy S,A don't come the result be b only.

Please elaborate this part.

Can you post your code So, I may try and understand what you are trying to do.

you know this is working with sets and the combinations of it,
I'm using it for my Automat project that I have to replace the variables that go to epsilon with the right production of these combinations,

the picture attached might describe it better then me,

but the duplicates have to be removed,

thanks

Umm I can't see a pattern to follow,

Would it be safe to say you want all possible Combinations. and there is only one input which is the string to be dissected?

hey,I was very confused with this at first,I was thinking that:"how cud I just replace one the characters in a string that has duplicates of that character",cuz replace method replaces all the characters,then I thought maybe "I have to use power set algorithm",then I realized I needed the index,so lastly I did it like this and it works,:)
it wasn't that hard but I don't know why didn't come to my mind at the first place.

private void Form1_Load(object sender, EventArgs e)
        {
            string str="SbSA";
            ArrayList arr_set=new ArrayList();
            arr_set.Add("A");
            arr_set.Add("S");

            ArrayList result =new ArrayList();
            result=combination(arr_set, str);
            label1.Text = Environment.NewLine;
            for(int i=0;i<result.Count;i++)
            label1.Text  += result[i].ToString() + Environment.NewLine;
        
         }
private ArrayList combination(ArrayList arr_get,string str_get)
        {

            ArrayList arr_result = new ArrayList();
            arr_result.Add(str_get);


            for(int count=0;count<arr_result.Count;count++)
            {
                string str = (string)arr_result[count];
                for (int i = 0; i < str.Length; i++)
                {
                    if (arr_get.Contains(str[i].ToString()))
                    {
                        string str_rmv = str.Remove(i, 1);
                        if(!arr_result.Contains(str_rmv))
                        arr_result.Add(str_rmv);
                    }
                }
               
            }
                return arr_result;
        }

what do you think?!

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.