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.?
check whether two string arrays contains the same numbers in differentcheck whether two string arrays contains the same numbers in different
Page 1 of 1
5 Replies - 5824 Views - Last Post: 04 March 2008 - 09:36 PM
#1
check whether two string arrays contains the same numbers in different
Posted 04 March 2008 - 02:55 AM
Replies To: check whether two string arrays contains the same numbers in different
#2
Re: check whether two string arrays contains the same numbers in different
Posted 04 March 2008 - 03:04 AM
Rajasree, 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.?
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;
#3
Re: check whether two string arrays contains the same numbers in different
Posted 04 March 2008 - 03:27 AM
Cr.java, on 4 Mar, 2008 - 03:04 AM, said:
Rajasree, 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.?
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.
#4
Re: check whether two string arrays contains the same numbers in different
Posted 04 March 2008 - 03:56 AM
Rajasree, on 4 Mar, 2008 - 03:27 AM, said:
Cr.java, on 4 Mar, 2008 - 03:04 AM, said:
Rajasree, 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.?
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;
#5
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
hope that help to get the idea;
Please use code tags when posting your code =>
This post has been edited by PsychoCoder: 04 March 2008 - 07:08 AM
#6
Re: check whether two string arrays contains the same numbers in different
Posted 04 March 2008 - 09:36 PM
Cr.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
hope that help to get the idea;
Please use code tags when posting your code =>
Thank you so much to all...
Problem is solved using these inputs..
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|