Basically i have a char array and i want to be able to count the number of duplicates from it.
Edit
Basically i was trying to make the terminal game from fallout. A pass-code will be entered and people will try to guess it. When guessing you will be told how many of these letters are correct and whether the length of the word is correct.
I use this to convert the actual word to an array
char[] ActualChar = new char[WordLenght];
while (ApproachingLenght < WordLenght)
{
foreach (char Letter in Word)
{
ActualChar[ApproachingLenght] = Letter;
ApproachingLenght++;
}
}
Guess into array
char[] GuessChar = new char[GuessLenght];
while (ApproachingGuessLenght < GuessLenght)
{
foreach (char Letter in Guess)
{
GuessChar[ApproachingGuessLenght] = Letter;
ApproachingGuessLenght++;
}
}
This to check for similarities between the two arrays, HOWEVER i get a problem here basically if the actual word is "Hello" and guess "Helli" it will say 6 characters are similar rather than 4. I found the problem to be the 2 l's as "abcd, asdf" did not have this issue.
if(GuessLenght == WordLenght)
{
for (int i = 0; i < WordLenght; i++)
{
for(int p = 0; p < WordLenght; p++)
{
if (GuessChar[i] == ActualChar[p])
{
LetterGuessed++;
}
}
}
}
else
{
if(GuessLenght> WordLenght)
{
Console.WriteLine("Wrong Lenght, Actual Lenght is : Shorter");
}
else
{
Console.WriteLine("Wrong Lenght, Actual Lenght is : Longer");
}
}
Therefore i planned to find the number of duplicates in the array and minus it from the letters guessed.
What I have tried:
string longText = @"your sentence comes here";
foreach (var character in CharacterCount.Count(longText))
{
if(character.Value>1)
Console.WriteLine("{0} - {1}", character.Key, character.Value);
}
This i found online and just added it.