From 62645703d1d15ec40b9b6ebfffd31091165ee360 Mon Sep 17 00:00:00 2001 From: Piotr Czajkowski Date: Sat, 1 Jan 2022 12:05:19 +0100 Subject: [PATCH] Starting sentence from capital letter --- 20_Buzzword/csharp/Program.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/20_Buzzword/csharp/Program.cs b/20_Buzzword/csharp/Program.cs index 1398d442..dcfdcd38 100644 --- a/20_Buzzword/csharp/Program.cs +++ b/20_Buzzword/csharp/Program.cs @@ -36,11 +36,19 @@ namespace Buzzword "performance", "reinforcement", "open classroom", "resource", "structure", "facility", "environment" }; + static string Capitalize(string input) + { + if (string.IsNullOrWhiteSpace(input)) + return string.Empty; + + return input.Substring(0, 1).ToUpper() + input[1..]; + } + static Random rnd = new Random(1); static string GeneratePhrase() { - return $"{Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length]} " + return $"{Capitalize(Phrases[(int)(13 * rnd.NextDouble() + 1) % Phrases.Length])} " + $"{Phrases[(int)(13 * rnd.NextDouble() + 14) % Phrases.Length]} " + $"{Phrases[(int)(13 * rnd.NextDouble() + 27) % Phrases.Length]}."; } @@ -54,8 +62,8 @@ namespace Buzzword { Console.WriteLine(); Console.WriteLine(GeneratePhrase()); - var answer = Console.ReadKey(); + var answer = Console.ReadKey(); if (answer.Key == ConsoleKey.N) break; }