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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:44:34+00:00 2026-05-30T15:44:34+00:00

I found very confusing when sorting a text file. Different algorithm/application produces different result,

  • 0

I found very confusing when sorting a text file. Different algorithm/application produces different result, for example, on comparing two string str1=";P" and str2="-_-"

Just for your reference here gave the ASCII for each char in those string:

char(';') = 59;   char('P') = 80;
char('-') = 45;   char('_') = 95;

So I’ve tried different methods to determine which string is bigger, here is my result:

  1. In Microsoft Office Excel Sorting command:

    “;P” < “-_-“

  2. C++ std::string::compare(string &str2), i.e. str1.compare(str2)

    “;P” > “-_-“

  3. C# string.CompareTo(), i.e. str1.CompareTo(str2)

    “;P” < “-_-“

  4. C# string.CompareOrdinal(), i.e. CompareOrdinal(w1, w2)

    “;P” > “-_-“

As shown, the result varied! Actually my intuitive result should equal to Method 2 and 4, since the ASCII(‘;’) = 59 which is larger than ASCII(‘-‘) = 45 .

So I have no idea why Excel and C# string.CompareTo() gives a opposite answer. Noted that in C# the second comparison function named string.CompareOrdinal(). Does this imply that the default C# string.CompareTo() function is not “Ordinal” ?

Could anyone explain this inconsistency?

And could anyone explain in CultureInfo = {en-US}, why it tells ;P > -_- ? what’s the underlying motivation or principle? And I have ever heard about different double multiplication in different cultureInfo. It’s rather a cultural shock..!

  • 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-30T15:44:35+00:00Added an answer on May 30, 2026 at 3:44 pm
    1. ?
    2. std::string::compare: “the result of a character comparison depends only on its character code”. It’s simply ordinal.
    3. String.CompareTo: “performs a word (case-sensitive and culture-sensitive) comparison using the current culture”. So,this not ordinal, since typical users don’t expect things to be sorted like that.
    4. String::CompareOrdinal: Per the name, “performs a case-sensitive comparison using ordinal sort rules”.

    EDIT: CompareOptions has a hint: “For example, the hyphen (“-“) might have a very small weight assigned to it so that “coop” and “co-op” appear next to each other in a sorted list.”

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

Sidebar

Related Questions

One thing I have continually found very confusing about using an object database like
I am currently reading Effective C# and found the following line very confusing: Last,
As a Flash newbie I found this very confusing and it cost me a
I am having a very confusing problem with an application I have been working
I found it very hard to customize PDF invoice that Magento use. Not only
I found a very interesting memory leak detector by using Visual C++. http://www.codeproject.com/KB/applications/visualleakdetector.aspx I
I found it very difficult to configure linked resource in Eclipse CDT. Folder wspolne
I've found it very difficult to find any existing documentation on this. What I'm
I haven't found a very good answer to my problem so I'm starting a
As a programmer I found it very hard to use my laptop and workstation

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.