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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:53:06+00:00 2026-05-25T11:53:06+00:00

I am using this var ordered = dictionary.Keys.OrderBy(x => x); to order a dictionary.

  • 0

I am using this var ordered = dictionary.Keys.OrderBy(x => x); to order a dictionary.

This works great ordering the dictionary alpha-numerically and I would like to keep it this way and add a few exceptions…

So right now, the ordered dictionary looks like this for the output:

1: "0603C" "113456" 1
2: "0603C" "984132" 8
3: "0603R" "11115" 3
4: "0603R" "13554" 1
5: "1608C_1.0" "119764" 2
6: "1608C_1.0" "147429" 54
7: "1608R_1.0" "122951" 4
8: "1608R_1.0" "147446" 1
9: "1608R_1.0" "147448" 23
10: "3216" "110762" 2
11: "TANT23" "119764" 2
//more here...

..but I would like it to look like this:

1: "0603R" "11115" 3
2: "0603R" "13554" 1
3: "0603C" "113456" 1
4: "0603C" "984132" 8
5: "1608R_1.0" "122951" 4    //**NOTICE**: The "R" and "C" endings after 1608 and 0603
6: "1608R_1.0" "147446" 1    // were switched. I would like to switch all "C" and "R"
7: "1608R_1.0" "147448" 23   // endings if they are the same value before.
8: "1608C_1.0" "119764" 2
9: "1608C_1.0" "147429" 54
10: "3216" "110762" 2
11: "TANT23" "119764" 2
//more here...

This is what my code looks like so far:

StreamWriter sw = new StreamWriter(saveFile.FileName);
Dictionary<string, int> dictionary = new Dictionary<string, int>();
List<string> lineList = new List<string>();
int j = 1;
lineList = theFuji1List.Select(line =>
{
    int nameLength = line.Name.Length;

    if (line.PartDescription != "")
        return line.PartDescription + " " line.PartNumber + " " + line.TWidth + " " + line.Name.Remove(1, nameLength - 1) + "\n";

    else
        return "N/A " + line.PartNumber + " " + line.TWidth + " " + line.Name.Remove(1, nameLength - 1) + "\n";
})
    .Where(x => !(x.Contains("FID") || x.Contains("EXCLUDE")))
    .ToLisT();

foreach (string word in lineList)
{
    if (dictionary.ContainsKey(word))
        dictionary[word]++;
    else
        dictionary[word] = 1;
}

var ordered = dictionary.Keys.Orderby(x => x);   //This is what I think I need to change?

foreach (string key in ordered)
{
    string[] splitKey = key.Split(' ');

    sw.WriteLine(string.Format("{0}: \"{1}\" \"{2}\" {3}", j, splitKey[0], splitKey[1], dictionary[key]));
    j++;
}
  • 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-25T11:53:06+00:00Added an answer on May 25, 2026 at 11:53 am

    Just modify the “R” to be a “B” for the sort expression, so that it falls before “C”:

    var ordered = dictionary.Keys.Orderby(x => Regex.Replace(x, @"^(\d+)R", "$1B"));
    

    This won’t modify your keys – it will only affect the sort.

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

Sidebar

Related Questions

I am using Cache in a web service method like this: var pblDataList =
How can I dynamically name id's using javascript? Something like this: js: var idName
I have a nested oredered list which i m animating using this code... var
I'm trying to do this: using(var context = new SampleEntities()) { User user =
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
Im using this code for mysql connection $con = mysql_connect(localhost:/var/lib/mysql/mysql.sock, abc , xyz); if
While using this code to serialize an object: public object Clone() { var serializer
Using this jquery code: <a href=javascript:void(0) id=m1>Get Selected id's</a> jQuery(#m1).click( function() { var s;
i am using this code <a onclick=javascript:var t=setInterval(GetUpdates(5,ajaxResult),300);>GetUpdates</a> but getting the syntax error
Hay, i'm using this script function preloader(images){ var i = 0; imageObj = new

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.