Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:16:53+00:00 2026-06-15T06:16:53+00:00

I have been set a task of creating a c# console text analysis program.

  • 0

I have been set a task of creating a c# console text analysis program. The program allows the user to enter a sentence word by word a single full stop is the end of the sentence a double full stop is to break the loop and give the analysis of the text

I have the program counting words and sentences correctly.

My question is: How can I change my code so that the program will not count full stops as a character?

Below is my code thus far

 case "1":

    string UserSentence="";
    string newString="";
    string UserWord;
    int SentenceCount=1;
    int WordCount=0;
    double CharCount=0;

    Console.WriteLine("You have chosen to type in your sentance(s) for analysis.\nPlease input each word then press enter.\n\nUse one full stop to end the sentence.\nUse two full stops to finish inputting sentences");
    while (true)
        {
            UserWord = Console.ReadLine();
            WordCount++;
            UserSentence = UserSentence+UserWord;


                if (UserWord == "..")
                    {
                        CharCount=CharCount-2;
                        WordCount--;
                        break;
                    }

                if (UserWord == ".")
                    {
                        CharCount=CharCount-1;
                        WordCount--;
                        SentenceCount++;
                    }
        }

    foreach (char c in UserSentence)

        {
            if (c ==' ')
            continue;
            newString += c;
        }
        CharCount = newString.Length;
        Console.WriteLine("Their are {0} characters",CharCount);
        Console.WriteLine("Their are {0} Sentences",SentenceCount);
        Console.WriteLine("Their are {0} Words",WordCount);
    break;

I have tried to correct the character count by subtracting 2 or 1 depending on the amount of full stops however it does not work

Thanks for any help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:16:54+00:00Added an answer on June 15, 2026 at 6:16 am

    Here you are simply overwriting the value of CharCount, discarding all the subtraction you did earlier:

    CharCount = newString.Length;
    

    It can be changed to:

    CharCount = CharCount + newString.Length;
    

    In order to give the correct result.

    There are other options, such as counting the number of . in the sentence, replacing all the . in a sentence in an empty string before getting its length and many more.

    Note on style: in C#, local variables are normally camelCase, not PascalCase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been task with (ha) creating an application that will allow the users
I have been tasked with creating an interactive 2D map application for a set
I have been set a task of natural language parsing in Prolog. So far
I have been given the task to create a shop website that allows users
I have been given the task of writing Powershell scripts to set up a
I have been set a project from school to design snake in VB.Net but
I have been set a challenge to create an indexer that takes all words
trying to display data only after variables have been set. $(document).ready(function () { function
I have been trying to set up Eclipse and the Arduino libraries. I have
I have been trying to set the scroll of my page to a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.