-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoveVowels_Demo.cs
70 lines (54 loc) · 1.87 KB
/
RemoveVowels_Demo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ExercisesProject.Exercises
{
// 0117 - Remove vowels
class RemoveVowels_Demo
{
//static void Main(string[] args)
public static void Run ()
{
Console.WriteLine("0117 - RemoveVowels_Demo");
Console.WriteLine();
string text = "Hello world!";
Console.WriteLine("Original text: {0}", text);
Console.WriteLine("Remove vowels v1: {0}", RemoveVowels_V1(text) );
Console.WriteLine("Remove vowels v2: {0}", RemoveVowels_V2(text) );
Console.WriteLine("Remove vowels v3: {0}", RemoveVowels_V3(text));
Console.ReadKey();
}
static string RemoveVowels_V1 ( string text )
{
StringBuilder result = new StringBuilder();
foreach( char c in text )
{
if ( !"aeiou".Contains( c.ToString().ToLower() ))
{
result.Append(c);
}
}
return result.ToString();
}
static string RemoveVowels_V2 ( string text )
{
string result = string.Empty;
var withoutVowels =
text.
Where(c => !"aeiou".Any(x => x.ToString() == c.ToString().ToLower()));
result = string.Concat(withoutVowels);
return result;
}
static string RemoveVowels_V3(string text)
{
string result = string.Empty;
var withoutVowels =
text.
Where( c =>
"aeiou".IndexOfAny(c.ToString().ToLower().ToCharArray()) == -1 );
result = string.Concat(withoutVowels);
return result;
}
}
}