diff --git a/text-counter-blazor/Program.cs b/text-counter-blazor/Program.cs index b72f499..9c1901b 100644 --- a/text-counter-blazor/Program.cs +++ b/text-counter-blazor/Program.cs @@ -3,8 +3,7 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddRazorComponents() - .AddInteractiveServerComponents(); +builder.Services.AddRazorComponents().AddInteractiveServerComponents(); var app = builder.Build(); @@ -21,7 +20,6 @@ app.UseStaticFiles(); app.UseAntiforgery(); -app.MapRazorComponents() - .AddInteractiveServerRenderMode(); +app.MapRazorComponents().AddInteractiveServerRenderMode(); app.Run(); diff --git a/text-counter-console-app/Program.cs b/text-counter-console-app/Program.cs index 4b651a5..2d12a82 100644 --- a/text-counter-console-app/Program.cs +++ b/text-counter-console-app/Program.cs @@ -1,14 +1,20 @@ -Console.WriteLine("Type text, then press Ctrl+D to calculate the number of characters, words and lines."); +Console.WriteLine( + "Type text, then press Ctrl+D to calculate the number of characters, words and lines." +); string textContent = ""; while (true) { - string textInput = Console.ReadLine();//read text input in each line - if (textInput == null | textInput == "")//if Ctrl+D is pressed or text input is empty + string textInput = Console.ReadLine(); //read text input in each line + if (textInput == null | textInput == "") //if Ctrl+D is pressed or text input is empty { - break;//end while loop + break; //end while loop } - textContent += textInput + '\n';//add text content from entered text input for each line + textContent += textInput + '\n'; //add text content from entered text input for each line } -Console.WriteLine($"Characters: {textContent.Length.ToString("N0")}");//number of characters -Console.WriteLine($"Words: {textContent.Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length.ToString("N0")}");//number of words -Console.WriteLine($"Lines: {textContent.Split('\n', StringSplitOptions.RemoveEmptyEntries).Length.ToString("N0")}");//number of lines \ No newline at end of file +Console.WriteLine($"Characters: {textContent.Length.ToString("N0")}"); //number of characters +Console.WriteLine( + $"Words: {textContent.Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length.ToString("N0")}" +); //number of words +Console.WriteLine( + $"Lines: {textContent.Split('\n', StringSplitOptions.RemoveEmptyEntries).Length.ToString("N0")}" +); //number of lines diff --git a/text-counter-razor/Pages/Error.cshtml.cs b/text-counter-razor/Pages/Error.cshtml.cs index 5069b99..6189b83 100644 --- a/text-counter-razor/Pages/Error.cshtml.cs +++ b/text-counter-razor/Pages/Error.cshtml.cs @@ -24,4 +24,3 @@ public void OnGet() RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; } } - diff --git a/text-counter-razor/Pages/Index.cshtml.cs b/text-counter-razor/Pages/Index.cshtml.cs index 04ff671..9a4ceda 100644 --- a/text-counter-razor/Pages/Index.cshtml.cs +++ b/text-counter-razor/Pages/Index.cshtml.cs @@ -12,8 +12,5 @@ public IndexModel(ILogger logger) _logger = logger; } - public void OnGet() - { - - } + public void OnGet() { } } diff --git a/text-counter-razor/Pages/TextCounter.cshtml.cs b/text-counter-razor/Pages/TextCounter.cshtml.cs index 981a11b..480ca10 100644 --- a/text-counter-razor/Pages/TextCounter.cshtml.cs +++ b/text-counter-razor/Pages/TextCounter.cshtml.cs @@ -4,15 +4,19 @@ public class TextCounterModel : PageModel { [BindProperty] - public string? textContent { get; set; }//text content string input from text box - public int characters { get; set; }//number of characters - public int words { get; set; }//number of words - public int lines { get; set; }//number of lines + public string? textContent { get; set; } //text content string input from text box + public int characters { get; set; } //number of characters + public int words { get; set; } //number of words + public int lines { get; set; } //number of lines + public void OnPost() { - textContent = Request.Form["textContent"];//get text box input - characters = textContent?.Length ?? 0;//update number of characters, words and lines based on entered text - words = textContent?.Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length ?? 0; + textContent = Request.Form["textContent"]; //get text box input + characters = textContent?.Length ?? 0; //update number of characters, words and lines based on entered text + words = + textContent + ?.Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) + .Length ?? 0; lines = textContent?.Split('\n', StringSplitOptions.RemoveEmptyEntries).Length ?? 0; } -} \ No newline at end of file +}