check whether two string arrays contains the same numbers in different

check whether two string arrays contains the same numbers in different

Page 1 of 1

5 Replies - 6734 Views - Last Post: 04 March 2008 - 09:36 PM Rate Topic: -----

#1 Rajasree  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 27-February 08

check whether two string arrays contains the same numbers in different

Posted 04 March 2008 - 02:55 AM

hi,


I have two string arrays with same length.

Is it possible to check whether two string arrays contains the same strings in different order.?

Can anybody help me out.?
Is This A Good Question/Topic? 0
  • +

Replies To: check whether two string arrays contains the same numbers in different

#2 Cr.java  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 22-February 08

Re: check whether two string arrays contains the same numbers in different

Posted 04 March 2008 - 03:04 AM

View PostRajasree, on 4 Mar, 2008 - 02:55 AM, said:

hi,


I have two string arrays with same length.

Is it possible to check whether two string arrays contains the same strings in different order.?

Can anybody help me out.?


Contains() method will help u;

it returns True if the input is available in that array;

hope that help u;
Was This Post Helpful? 0
  • +
  • -

#3 Rajasree  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 27-February 08

Re: check whether two string arrays contains the same numbers in different

Posted 04 March 2008 - 03:27 AM

View PostCr.java, on 4 Mar, 2008 - 03:04 AM, said:

View PostRajasree, on 4 Mar, 2008 - 02:55 AM, said:

hi,


I have two string arrays with same length.

Is it possible to check whether two string arrays contains the same strings in different order.?

Can anybody help me out.?


Contains() method will help u;

it returns True if the input is available in that array;

hope that help u;




But the strings can be duplicated.

for eg,

Array 1 Array 2
A C
B C
C E
C A
D B
E D

what we need is ,we have to check whether the array2 is a duplicate of array1 , but in array2 ,items can be in different order.
Was This Post Helpful? 0
  • +
  • -

#4 Cr.java  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 22-February 08

Re: check whether two string arrays contains the same numbers in different

Posted 04 March 2008 - 03:56 AM

View PostRajasree, on 4 Mar, 2008 - 03:27 AM, said:

View PostCr.java, on 4 Mar, 2008 - 03:04 AM, said:

View PostRajasree, on 4 Mar, 2008 - 02:55 AM, said:

hi,


I have two string arrays with same length.

Is it possible to check whether two string arrays contains the same strings in different order.?

Can anybody help me out.?


Contains() method will help u;

it returns True if the input is available in that array;

hope that help u;


But the strings can be duplicated.

for eg,

Array 1 Array 2
A C
B C
C E
C A
D B
E D

what we need is ,we have to check whether the array2 is a duplicate of array1 , but in array2 ,items can be in different order.



ok thats fine just make sure that the number of "Occurrence" in both arrays are Equal;
Was This Post Helpful? 0
  • +
  • -

#5 Cr.java  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 22-February 08

Re: check whether two string arrays contains the same numbers in different

Posted 04 March 2008 - 04:31 AM

public static void Main(string[] args)
        {
            string[] s = { "www", "ww", "wwk", "ww2" };
            string[] s1 = { "www", "wwk", "ww2", "ww2" };
            bool duplicated= false;
            int i = 0;
            while (true)
            {
                if (s.Contains(s1[i]))
                {
                    int a4s = occurrence(s, s1[i]);
                    int a4s1 = occurrence(s1, s1[i]);
                    if (a4s != a4s1)
                    {
                        break;
                    }
                    else
                    {
                        if(i==s.Length-1)
                        {
                            duplicated= true;
                            break;
                        }
                        else{
                        }
                        i++;
                    }
                    
                 }
                    
                else
                {
                    break;
                }
            }
            Console.WriteLine(duplicated);


        }
        public static int occurrence(string [] a, string a2)
        {
            int occ = 0;
            for (int i = 0; i < a.Length;i++ )
            {
                if(a[i].Equals(a2))
                {
                    occ++;
                }

            }
            return occ;
        }
  
    }



am beginner like u ^_^ please have a look at it carefully;
hope that help to get the idea;


Please use code tags when posting your code => :code:

This post has been edited by PsychoCoder: 04 March 2008 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#6 Rajasree  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 27-February 08

Re: check whether two string arrays contains the same numbers in different

Posted 04 March 2008 - 09:36 PM

View PostCr.java, on 4 Mar, 2008 - 04:31 AM, said:

public static void Main(string[] args)
        {
            string[] s = { "www", "ww", "wwk", "ww2" };
            string[] s1 = { "www", "wwk", "ww2", "ww2" };
            bool duplicated= false;
            int i = 0;
            while (true)
            {
                if (s.Contains(s1[i]))
                {
                    int a4s = occurrence(s, s1[i]);
                    int a4s1 = occurrence(s1, s1[i]);
                    if (a4s != a4s1)
                    {
                        break;
                    }
                    else
                    {
                        if(i==s.Length-1)
                        {
                            duplicated= true;
                            break;
                        }
                        else{
                        }
                        i++;
                    }
                    
                 }
                    
                else
                {
                    break;
                }
            }
            Console.WriteLine(duplicated);


        }
        public static int occurrence(string [] a, string a2)
        {
            int occ = 0;
            for (int i = 0; i < a.Length;i++ )
            {
                if(a[i].Equals(a2))
                {
                    occ++;
                }

            }
            return occ;
        }
  
    }



am beginner like u ^_^ please have a look at it carefully;
hope that help to get the idea;


Please use code tags when posting your code => :code:



Thank you so much to all...:)
Problem is solved using these inputs..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1