-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
63 lines (48 loc) · 1.64 KB
/
Program.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
internal class Program
{
/// <param name="args">The files to read</param>
/// <param name="number">Print Numbers?</param>
/// <param name="showEnds">Put an "$" at the End?</param>
private static void Main(string[] args, bool number = false, bool showEnds = false)
{
if (args.Length == 0) PrintFromSTDIN(number, showEnds);
string text = "";
foreach (string file in args)
{
try
{
text += File.ReadAllText(file);
}
catch (System.IO.FileNotFoundException)
{
Console.WriteLine($"{file} file not found!");
return;
}
}
Console.Write(ParseString(text, number, showEnds));
}
public static string ParseString(string text, bool number, bool showEnds)
{
if (number) text = AddNumbers(text);
if (showEnds) text = AddEnds(text);
return text;
}
public static void PrintFromSTDIN(bool number, bool showEnds)
{
while (true) Console.WriteLine(Console.ReadLine());
}
public static string AddEnds(string text)
{
var splitText = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
text = "";
for (var i = 0; i < splitText.Length - 1; i++) text += $"{splitText[i]}$ \n";
return text;
}
public static string AddNumbers(string text)
{
var splitText = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
text = "";
for (var i = 0; i < splitText.Length - 1; i++) text += $" {i} {splitText[i]}\n";
return text;
}
}