简体   繁体   中英

Sorting strings in MFC vs. C#

I have a legacy app that uses both C# and native C++ (MFC). I need to sort strings on both sides so that they are in the same order. The problem is that on the .NET side using string.Compare it comes out in a "culture-specific" way so that, for instance, "A_B" sorts before "A11" whereas in MFC, using operator < , "A11" sorts before "A_B".

I know I can change the .NET side to use Ordinal sorting, but that could break some foreign language sorting. What I want is to change the MFC sorting so that it sorts in a "culture-specific" manner, like the .NET side. I found CompareStringEx in the Win32 API, but am wondering if there is an MFC solution to this or something else I am missing.

Thanks in advance.

MFC's CString class has Collate and CollateNoCase for locale-specific comparisons. I haven't tested them to assure they match .NETs collation order, but I'd expect that both use the same Win32 function(s), in which case they'd obviously match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM