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

  • Home
  • SEARCH
  • 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 730589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:55:46+00:00 2026-05-14T06:55:46+00:00

i’m quite a beginner in C# , i tried to write a program that

  • 0

i’m quite a beginner in C# , i tried to write a program that extract words from an entered string, the user has to enter a minimum length for the word to filter the words output … my code doesn’t look good or intuitive, i used two arrays countStr to store words , countArr to store word length corresponding to each word .. but the problem is i need to use hashtables instead of those two arrays , because both of their sizes are depending on the string length that the user enter , i think that’s not too safe for the memory or something ?

here’s my humble code , again i’m trying to replace those two arrays with one hashtable , how can this be done ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication2
{
class Program
{

    static void Main(string[] args)
    {
        int i = 0 ;
        int j = 0;
        string myString = "";
        int counter = 0;
        int detCounter = 0;          

        myString = Console.ReadLine();
        string[] countStr = new string[myString.Length];
        int[] countArr = new int[myString.Length];

        Console.Write("Enter minimum word length:");
        detCounter = int.Parse(Console.ReadLine());

        for (i = 0; i < myString.Length; i++)
        {
            if (myString[i] != ' ')
            {
                counter++;
                countStr[j] += myString[i];
            }
            else
            {
                countArr[j] = counter;
                counter = 0;
                j++;
            }                                               
        }

        if (i == myString.Length)
        {
            countArr[j] = counter;
        }

        for (i = 0; i < myString.Length ; i++)
        {
           if (detCounter <= countArr[i])
            {
                Console.WriteLine(countStr[i]);
            }   
        }

     Console.ReadLine();     

    }        
  }
 } 
  • 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-05-14T06:55:47+00:00Added an answer on May 14, 2026 at 6:55 am

    You’re not doing too badly for a first attempt but this could be a lot better.

    First thing: use TryParse rather than Parse when parsing an integer input by a human. If the human types in “HELLO” instead of an integer, your program will crash if you use Parse; only use Parse when you know that it is an integer.

    Next thing: consider using String.Split to split the string into an array of words, and then process the array of words.

    Next thing: code like yours that has a whole lot of array mutations is hard to read and understand. Consider characterizing your problem as a query. What are you trying to ask? I’m not sure I completely understand your code but it sounds to me like you are trying to say “take this string of words separated by spaces. Take a minimum length. Give me all the words in that string which are more than the minimum length.” Yes?

    In that case, write the code that looks like that:

    string sentence = whatever;
    int minimum = whatever;
    var words = sentence.Split(' ');
    var longWords = from word in words 
                    where word.Length >= minimum 
                    select word;
    foreach(var longWord in longWords) 
        Console.WriteLine(longWord);
    

    And there you go. Notice how the code reads like what it is doing. Try to write code so that the code conveys the meaning of the code, not the mechanism of the code.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

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.