Skip to content

Commit

Permalink
Format C# code
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Nov 8, 2024
1 parent f7aba90 commit 7f78309
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
6 changes: 2 additions & 4 deletions text-counter-blazor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -21,7 +20,6 @@
app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

app.Run();
22 changes: 14 additions & 8 deletions text-counter-console-app/Program.cs
Original file line number Diff line number Diff line change
@@ -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
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
1 change: 0 additions & 1 deletion text-counter-razor/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ public void OnGet()
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}

5 changes: 1 addition & 4 deletions text-counter-razor/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ public IndexModel(ILogger<IndexModel> logger)
_logger = logger;
}

public void OnGet()
{

}
public void OnGet() { }
}
20 changes: 12 additions & 8 deletions text-counter-razor/Pages/TextCounter.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 7f78309

Please sign in to comment.