This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextTransform.cs
93 lines (80 loc) · 2.46 KB
/
TextTransform.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace lab_02
{
public class TextTransform
{
private static readonly Random RandomInstance = new Random();
public static string ToTitleCase(string text)
{
return Regex.Replace(text, @"(^\w)|(\s\w)", m => m.Value.ToUpper());
}
public static int GetRandomInt()
{
return RandomInstance.Next(0, 9);
}
public static string ReplaceVowels(string text)
{
var characters = text.ToCharArray();
for (var i = 0; i < characters.Length; i++)
{
var c = characters[i];
if ("aeiou".Contains(char.ToLower(c)))
{
characters[i] = GetRandomInt().ToString().ToCharArray()[0];
}
}
return new string(characters);
}
public static string DoubleUpperCaseLetters(string text)
{
var characters = text.ToCharArray().Select(ch => ch.ToString()).ToArray();
for (var i = 0; i < characters.Length; i++)
{
var c = characters[i];
if (char.IsUpper(c.ToCharArray()[0]))
{
characters[i] = c + c;
}
}
return string.Join("", characters);
}
public static string RemoveThirdWord(string text)
{
var words = text.Split(' ');
for (var i = 0; i < words.Length; i++)
{
if (i == 2)
{
words[i] = "";
}
}
return string.Join(" ", words);
}
public static string InsertMiracle(string text)
{
var words = text.Split(' ');
for (var i = 0; i < words.Length; i++)
{
if (i == 4)
{
words[i] = words[i] + " miracle ";
}
}
return string.Join(" ", words);
}
public static string Join78(string text)
{
var words = text.Split(' ');
for (var i = 0; i < words.Length; i++)
{
if (i == 6 && words.Length > 6)
{
words[i] = string.Join("Joined", words[i], words[i + 1]);
}
}
return string.Join(" ", words);
}
}
}