Click here to Skip to main content
15,898,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The program needs to arrange words as word families based on the letter the user inputs. And I have selected words that contain a letter and don't contain a letter by specifying the letter as a variable to make it easier to understand initially, I need help in trying to select the words that have two e's and the words that has two consecutive e's if any.

What I have tried:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace LINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] words = { "ally", "beta", "cool", "deal", "else", "good" };

            char letter = 'e';
            List<String> wordFamilies = new List<String>();
            foreach (String word in words.Where(word => word.Contains(letter)))
            {
                wordFamilies.Add(word);
            }

            

            wordFamilies.ToList().ForEach(Console.WriteLine);
        }
    }
}
Posted
Updated 28-Oct-21 15:59pm
v3

1 solution

1) even though it won't cause a compile error, using LINQ, or any other reserved name, that is identical (except for character casing) for a MS defined term is a very bad practice: it may make your code seem ambiguous.

2) you don't do anything with 'doubleFamilies.

3) if you can find 'e, finding 'ee is just a matter of your studying string.Contains: [^]; look at the overloads.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900