Skip to content

Commit 6f85689

Browse files
committed
Add ASP.NET text counter console application using C#
1 parent 6f46151 commit 6f85689

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
**/bin
44
**/obj
55
**/.DS_Store
6-
text-counter-asp-net.sln
6+
text-counter-asp-net-application.sln
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Console.WriteLine("Type text, then press Ctrl+D to calculate the number of characters, words and lines.");
2+
string textContent = "";
3+
while (true)
4+
{
5+
string textInput = Console.ReadLine();//read text input in each line
6+
if (textInput == null | textInput == "")//if Ctrl+D is pressed or text input is empty
7+
{
8+
break;//end while loop
9+
}
10+
textContent += textInput + '\n';//add text content from entered text input for each line
11+
}
12+
Console.WriteLine($"Characters: {textContent.Length}");//number of characters
13+
Console.WriteLine($"Words: {textContent.Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length}");//number of words
14+
Console.WriteLine($"Lines: {textContent.Split('\n', StringSplitOptions.RemoveEmptyEntries).Length}");//number of lines
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>text_counter_console_app</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
</Project>

0 commit comments

Comments
 (0)