c#-如何删除字符串数组中的元音字母?

标签 c#

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

namespace myApp  
{    
    class Program
    {
        static void Main(string[] args)
        {
            string[] vowels = new string[]{"A","a","E","e","I","i","O","o","U","u"};
            for(int j=0;j<vowels.Length;j++)
            {
                string[] names = new string[5];
                names[0] = "john";
                names[1] = "samuel";
                names[2] = "kevin";
                names[3] = "steve";
                names[4] = "martyn";
            for (int i = 0; i < names.Length; i++)
            {
               if(vowels[j]==names[i])
               {

               }
            }


                Console.WriteLine("The output is:"+names[i]);
            }
                Console.ReadLine();
        }
    }
}

谁能帮我如何从给定名称中删除元音字母并在控制台中显示它们?

最佳答案

你可以使用 Linq

string[] names = new string[5];
names[0] = "john";
names[1] = "samuel";
names[2] = "kevin";
names[3] = "steve";
names[4] = "martyn";

var vowels = new HashSet<char>("AaEeIioUu");


names = names.Select(Name => string.Concat(Name.Where(C => !vowels.Contains(C))))
             .ToArray();

Console.WriteLine(string.Join(Environment.NewLine, names));

关于c#-如何删除字符串数组中的元音字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32871261/

相关文章:

c# - 获取日历的工作时间需要什么权限?

c# - 这是一种安全且*相对可行*的异步记录某些事件的方法吗?

c# - 在 Catch block 中重试?

c# - Listbox 所选项目内容到文本 block

c# - 返回一个与声明的结构不同的结构,为什么它可以正确? C#

c# - Json.NET - CustomCreationConverter 中单个属性的默认反序列化行为

c# - 将 NServiceBus Saga 作为单个可等待的请求-响应调用

c# - 跳过 SqlBulkCopy 中的某些列

c# - 我将如何创建一个程序来获取名称列表并将它们分类为偶数组?

c# - 将物理电话上的 Xamarin.forms 应用程序连接到 Asp.net REST API 时,StatusCode 400 "Bad request"