Welcome to Dream.In.Code
Become a C# Expert!

Join 150,392 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,053 people online right now. Registration is fast and FREE... Join Now!




check whether two string arrays contains the same numbers in different

 
Reply to this topicStart new topic

check whether two string arrays contains the same numbers in different, check whether two string arrays contains the same numbers in different

Rajasree
4 Mar, 2008 - 01:55 AM
Post #1

New D.I.C Head
*

Joined: 27 Feb, 2008
Posts: 10

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.?



User is offlineProfile CardPM
+Quote Post

Cr.java
RE: Check Whether Two String Arrays Contains The Same Numbers In Different
4 Mar, 2008 - 02:04 AM
Post #2

New D.I.C Head
*

Joined: 22 Feb, 2008
Posts: 19



Thanked: 1 times
My Contributions
QUOTE(Rajasree @ 4 Mar, 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.?


Contains() method will help u;

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

hope that help u;
User is offlineProfile CardPM
+Quote Post

Rajasree
RE: Check Whether Two String Arrays Contains The Same Numbers In Different
4 Mar, 2008 - 02:27 AM
Post #3

New D.I.C Head
*

Joined: 27 Feb, 2008
Posts: 10

QUOTE(Cr.java @ 4 Mar, 2008 - 03:04 AM) *

QUOTE(Rajasree @ 4 Mar, 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.?


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.





User is offlineProfile CardPM
+Quote Post

Cr.java
RE: Check Whether Two String Arrays Contains The Same Numbers In Different
4 Mar, 2008 - 02:56 AM
Post #4

New D.I.C Head
*

Joined: 22 Feb, 2008
Posts: 19



Thanked: 1 times
My Contributions
QUOTE(Rajasree @ 4 Mar, 2008 - 03:27 AM) *

QUOTE(Cr.java @ 4 Mar, 2008 - 03:04 AM) *

QUOTE(Rajasree @ 4 Mar, 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.?


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;



User is offlineProfile CardPM
+Quote Post

Cr.java
RE: Check Whether Two String Arrays Contains The Same Numbers In Different
4 Mar, 2008 - 03:31 AM
Post #5

New D.I.C Head
*

Joined: 22 Feb, 2008
Posts: 19



Thanked: 1 times
My Contributions
csharp

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 happy.gif please have a look at it carefully;
hope that help to get the idea;


Please use code tags when posting your code => code.gif

This post has been edited by PsychoCoder: 4 Mar, 2008 - 06:08 AM
User is offlineProfile CardPM
+Quote Post

Rajasree
RE: Check Whether Two String Arrays Contains The Same Numbers In Different
4 Mar, 2008 - 08:36 PM
Post #6

New D.I.C Head
*

Joined: 27 Feb, 2008
Posts: 10

QUOTE(Cr.java @ 4 Mar, 2008 - 04:31 AM) *

csharp

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 happy.gif please have a look at it carefully;
hope that help to get the idea;


Please use code tags when posting your code => code.gif



Thank you so much to all...smile.gif
Problem is solved using these inputs..

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:57PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month