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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:17:07+00:00 2026-06-10T01:17:07+00:00

I need some help. Basically, I have a paragraph of text in a text

  • 0

I need some help. Basically, I have a paragraph of text in a text file, and I need to read the textfile (stored as a string) into a List of characters and stores the amount of time they appear inside the string. So it will produce a list between (A-Z) and order it depending on how many times the characters appear. Is there a way to do this without using LINQ.

Thank you 🙂

  • 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-10T01:17:09+00:00Added an answer on June 10, 2026 at 1:17 am

    An efficient and easy way is to create a ConcurrentDictionary with the char as key and the number it appears as value. It has the nice AddOrUpdate(upsert) method:

    string text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
    var chars = new System.Collections.Concurrent.ConcurrentDictionary<char, int>();
    foreach (char c in text)
    {
       chars.AddOrUpdate(c, 1, (chr, count) => count + 1);
    }
    

    If you want to order it by the number without Linq(Lambda != Linq) you can use this code:

    List<KeyValuePair<char, int>> charList = chars.ToList();
    charList.Sort((firstPair, nextPair) =>
    {
        return firstPair.Value.CompareTo(nextPair.Value);
    });
    

    Edit: If you want to order descending change above a little bit:

    charList.Sort((firstPair, nextPair) =>
    {
        return -(firstPair.Value.CompareTo(nextPair.Value));
    });
    

    result:

    Console.Write(string.Join(Environment.NewLine, charList.Select(kv => string.Format("Char={0} Num={1}", kv.Key, kv.Value))));
    
    Char=  Num=90
    Char=e Num=59
    Char=t Num=43
    Char=s Num=39
    Char=n Num=38
    Char=i Num=32
    Char=a Num=28
    Char=o Num=25
    Char=r Num=24
    Char=p Num=18
    Char=m Num=18
    Char=l Num=17
    Char=u Num=17
    Char=d Num=16
    Char=h Num=14
    Char=y Num=13
    Char=g Num=11
    Char=c Num=10
    Char=k Num=7
    Char=w Num=6
    Char=f Num=6
    Char=I Num=6
    Char=v Num=5
    Char=b Num=5
    Char=L Num=5
    Char=, Num=4
    Char=. Num=4
    Char=0 Num=3
    Char=x Num=2
    Char=1 Num=2
    Char=' Num=1
    Char=5 Num=1
    Char=M Num=1
    Char=A Num=1
    Char=P Num=1
    Char=6 Num=1
    Char=9 Num=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a linq query. Basically, I have a datatable with
basically i need some algorithm that fits into the following problem: i have 5
I need some help with defining a dynamic method. Basically, I have many classes
I need some help with this. Basically I have the following code which I
I need some help here. Basically, I have an Activity. This uses the startActivityForResult()
I need some help on this one please, i basically have menuVIP.java, and vipKeyword.java.
I'm working with some php and need some help. Basically I have a script
I need some help choosing databases for my application. My web application will basically
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help, please. I have a line of horizontal thumbnails loaded as ONE

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.