Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
6
Reply
duplicates in a string count ? help required
SUNIL GUTTA
10 years ago
795
Reply
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
Post
Reset
Cancel
Answers (
6
)
Next Recommended Forum
WordFind Puzzle
Word prediction using n-gram technique