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

  • Home
  • SEARCH
  • 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 184789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:21:16+00:00 2026-05-11T15:21:16+00:00

I need to sort an array containing a list of words and search the

  • 0

I need to sort an array containing a list of words and search the same using binarysearch. For certain reasons, the word-list must always be sorted using the sorting-rules of ‘en-US’ i.e. American Regional Settings. The code will run under various international Operating Systems and of course, this will mean that the word-list will be sorted differently according to the local Regional Settings in use. One problem could arise on a computer/device running with Lithuanian Regional Settings. Why? Because the letter ‘Y‘ in most languages is sorted like X-Y-Z while in Lithuanian, the sort order is I-Y-J. This behavior would create havoc to my program.

On a desktop-PC, I could change momentarily the Regional Settings into American English by using:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(‘en-US’)

However, since I am developing for Windows Mobile (CF.NET), this piece of code is not possible to implement.

I found some hacks which could let me change the Regional Settings on the device programmatically but they are not ‘official’ and considered risky so I prefer avoiding these.

So my question is: how can I force Array.Sort and Array.BinarySearch to use CultureInfo = ‘en-US’ while sorting and searching regardless of the Regional Settings set on the device?

I believe I could use:

Public Shared Function BinarySearch(Of T) ( _     array As T(), _     value As T, _     comparer As IComparer(Of T) _ ) As Integer 

and implement Comparer to take into consideration CultureInfo (and set it to ‘en-US’) but I don’t know how to do that despite trying hard. If anyone could post some sample-code in VB.Net or C# or an explanation of how to do it, I would be very grateful.

If you are aware of any alternative solution which works in CF.Net, then, of course, I am all ears.

Thanks.

EDIT:

I will consider Twanfosson’s answer as the accepted solution since my question clearly stated that I wanted to maintain an association with the English language.

However, in means of flexibility, I believe Guffa’s answer is the best one. Why? Let’s use another example: In German, the letter Ö is sorted Ö-X-Z while in Swedish and Finnish, the order is X-Z-Ö. In Estonian the sort order is Z-Ö-X. Complicated, isn’t it? Guffa’s solution will let me force Swedish sorting-order (changing CultureInfo) on a device running under German Regional settings. Using Comparer.DefaultInvariant with its association to English wouldn’t help in this case, probably the letter Ö would end up with O. Therefore my vote will go to Guffa.

  • 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. 2026-05-11T15:21:17+00:00Added an answer on May 11, 2026 at 3:21 pm

    Is it not possible to use the Invariant culture?

    InvariantCulture retrieves an instance of the invariant culture. It is associated with the English language but not with any country/region.

    Using the invariant culture would make this trivial.

    Array.Sort( myArray, Comparer.DefaultInvariant );  Array.BinarySearch( myArray, myString, Comparer.DefaultInvariant ); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to sort an array containing arrays in ascending numerical order. The data
Hi I've got this list of li's, containing dynamic classes(not always the same). There's
i need to sort an string Array and it MUST be sorted by ascii.
I need to sort an array of dictionaries, using a keyed object from the
I need to sort an array of ints using a custom comparator, but Java's
Long story short, I need to sort an array of objects using usort, and
I need to sort an array that can look like this: $array[4][0] = array('id'
I need to sort an array of months (alphabetical months) according to their months
I have an array which i need to sort its elements by occurrence then
I have this array and I need to sort it, first by key_1 and

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.