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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:51:16+00:00 2026-06-02T03:51:16+00:00

I have UK postcodes data and I would like to sort them alphabeticaly, when

  • 0

I have UK postcodes data and I would like to sort them alphabeticaly, when I do that the result is as follows;

N10-XX
N1-XX
N2-XX
N3-XX
N4-XX
N5-XX

What I want is that as follows;

N1-XX
N2-XX
N3-XX
N4-XX
N5-XX
N10-XX

Basicaly I need to add 0 at the begining of the number if it is 1 digit. like N1 should be N01 to be able to do that, what is the regexp pattern for that?

Many thanks.

  • 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-02T03:51:17+00:00Added an answer on June 2, 2026 at 3:51 am

    Well if you are bent on using Regex, then this should do it

    var text = @"N10-XX
    N1-XX
    N2-XX
    N3-XX
    N4-XX
    N5-XX";
    
    text = Regex.Replace(text, @"^N(\d)-", "N0$1-", RegexOptions.Multiline);
    

    that said you obviously will be altering the original data, so I am not sure if this is even applicable

    If you want to sort numerically, but preserve the original data, then you may need to do something like this

    text.Split('\n')
        .Select(o => new { Original = o, Normal = Regex.Replace(o, @"^N(\d)-", "N0$1-", RegexOptions.Compiled)})
        .OrderBy(o => o.Normal)
        .Select(o => o.Original)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of contacts and a table of postcode data. I need
I need to re-format a list of UK postcodes and have started with the
I have a class that stores data in asp.net c# application that never changes.
I have the following table which holds data on customers and staff. Would it
I have 700.000 street names, 8111 municipality names, and 80333 locality postcodes. I would
I have a repeater that lists data including an ID that I pass to
I have this class that tries multiple methods of getting data from Google maps
I have my data in a variable which when output looks something like this
I have some XML and need to be able to read the data within.
I got this problem. I have a form that retrieves a table data using

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.