SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 394k

duplicates in a string count ? help required

Feb 16 2014 2:34 AM
Hi
 
Please help me that my program gives correct output .
 
My program :
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace part1
{
class AQ
{
static void Main()
{
int count; int z=0;
string s = "twinkle twinkle little star how i wonder what u star little ";
string[] arr = s.Split(' ');
int length = arr.Length - 1;
for (int i = 0; i < length; i++)
{
count = 0;
for (int j = 0; j < length; j++)
{
if (arr[i] == arr[j])
{
count += 1;
}
}
if (i > 0)
{
if (count > 1)
{
Console.WriteLine(" {0} - {1} ", arr[i], count);
}
}
Console.ReadKey();
}
}
}
 
I am getting output like :
twinkle-2
twinkle-2
star-2
star-2
little-2
little-2
 
BUT I NEED LIKE only  
 
twinkle-2
star-2
little-2 
 
Thank you 
 
 
 
 

Answers (6)