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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:42:50+00:00 2026-05-13T18:42:50+00:00

I always assumed that .Net compares strings lexicographically, according to the current culture. But

  • 0

I always assumed that .Net compares strings lexicographically, according to the current culture. But there is something strange when one of the strings ends on ‘-‘:

"+".CompareTo("-")
Returns: 1

"+1".CompareTo("-1")
Returns: -1

I get it an all cultures I tried, including the invariant one.
Can anyone explain what is going on, and how can I get the consistent character-by-character ordering for the current locale?

  • 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-13T18:42:50+00:00Added an answer on May 13, 2026 at 6:42 pm

    There isn’t necessarily a consistent character-by-character ordering for any particular locale.

    From the MSDN documentation:

    For example, a culture could specify that certain combinations of characters
    be treated as a single character, or uppercase and lowercase characters
    be compared in a particular way, or that the sorting order of a character
    depends on the characters that precede or follow it.

    The only way to ensure consistent character-by-character ordering is by using an ordinal comparison, as demonstrated in Anton’s answer.

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

Sidebar

Related Questions

In pre-.NET world I always assumed that int is faster than byte since this
For some reason I have always assumed that most of the time a variable
Why do IDE's complain about leaking this in constructor? I've always assumed that it's
I've always felt like SecureString was a little odd, but assumed most of my
I always read that one reason to chose a RESTful architecture is (among others)
In the past, when writing my code, I always assumed that the model should
Assuming that I'm talking about an ASP.NET MVC 3 application, the scenario is something
I've always assumed that DbNull.value was a singleton. And thus you could do things
Is it safe to always assume that HttpContext.Current will be non-null in Application_PreRequestHandlerExecute? EDIT:
I always assumed that some_function(...) was exactly the same as some_function.call(this, ...) . This

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.