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 8858325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:48:09+00:00 2026-06-14T14:48:09+00:00

Hello im a bit stuck i dont know how to find the third longest

  • 0

Hello im a bit stuck i dont know how to find the third longest word in a string, i have got my code to find the longest but i cant manage to get it to find the third longest. any help?

public void longestWord()
    {
        string sentance, word;
        word = " ";
        char[] a = new char[] { ' ' };
        sentance = textBox1.Text;  //<--string here


        foreach (string s1 in sentance.Split(a))
        {
            if (word.Length < s1.Length)
            {
                word = s1;
            }
        }
        label9.Text = ("The longest word is " + word + " and its length is " + word.Length + " characters long");
    }

P.S an example of the string im testing is:

    1.

DarkN3ss is my most experienced provider of Windows based business solutions. I focus on delivering my business value in best possible understanding of this technologies and directions.
DarkN3ss recognising me as an “elite business partner” for implementing solutions based on my capabilities and experience with Windows and Linux products.

  • 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-14T14:48:10+00:00Added an answer on June 14, 2026 at 2:48 pm

    Solution: To get all the third largest words

       string[] splitStr = sentence.Split(' ');
    
       if (splitStr.Length > 2)
       {
            List<int> allLengths = splitStr.Select(x => x.Length).Distinct().ToList();
    
            int thirdLargestWordLength = allLengths.OrderByDescending(x => x)
                                                   .Skip(2).Distinct().Take(1).FirstOrDefault();
    
            if (splitStr[0].Length != thirdLargestWordLength && 
             splitStr[1].Length != thirdLargestWordLength)
             {
    
                string[] theThirdLargestWords = splitStr.Where(x => x.Length == thirdLargestWordLength)
                                                                      .ToArray();
    
    
                 if (theThirdLargestWords.Length == 1)
                 {
                    label9.Text = "The third longest word is " + theThirdLargestWords[0];
                 }
                 else
                 {
                    string words = "";
    
                    for (int i = 0; i < theThirdLargestWords.Length; i++)
                    {
                       if (i == 0)
                       {
                         words = theThirdLargestWords[i];
                    }
                   //else if ((i + 1) == theThirdLargestWords.Length)
                   //{
                   //   words += " and " + theThirdLargestWords[i];
                   //}
                    else
                    {
                        words += ", " + theThirdLargestWords[i];
                    }
                 }
    
                 label9.Text = "The third longest words are " + words;
            }
          }
       }
    

    I commented out the “and” part as i’m not sure if you want that in your string. I also added the first if statement so you don’t get an error if you have less then 3 words.

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

Sidebar

Related Questions

Hell there, I have been stuck on this for a bit now. I know
Hello i'm learning a bit JSP and i have a problem with the code
Hello I have this bit of code, and it what it must do is
Hello (and thanks in advance) I'm in a bit of a quandry, I cant
hello fellow java developers. I'm having a bit of an issue here. I have
(I've removed attributes, but it's a bit of auto-generated HTML.) <img class=p/> <div> hello
So I am trying to run console 64 bit Hello World program. I have
Hello Im a bit lost n the priority queues and comparator. I dont really
Hello I've a small bit of code how could I give link to both
Hello cool so I think I have a good question for a bit of

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.