c#-how to delete vowels in an array of string? -


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";             (int = 0; < names.length; i++)             {                if(vowels[j]==names[i])                {                 }             }                   console.writeline("the output is:"+names[i]);             }                 console.readline();         }     } } 

can me how delete vowels given names , display them in console?

eser's answer succinct , correct way this, in case want more fine-grain control on when , vowels you're removing, try like:

string[] names = new string[5]; names[0] = "john"; names[1] = "samuel"; names[2] = "kevin"; names[3] = "steve"; names[4] = "martyn";  list<char> vowels = new list<char>("aaeeiioouuyy".tochararray());  for(int = 0; < names.length; i++) {     string name = names[i];     string trimmedname = name;      foreach(char vowel in vowels) {         int vowelindex;         while((vowelindex = trimmedname.indexof(vowel)) != -1) {             trimmedname = trimmedname.substring(0, vowelindex) + trimmedname.substring(vowelindex + 1);         }      }     name = trimmedname; } 

this bit more explicit, less performant, , more ugly though -- may want go original solution.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -