?
Solved

String compare on non-English names?

Posted on 2010-11-11
5
Medium Priority
?
482 Views
Last Modified: 2013-11-20
In Visual C++, how do I compare two names so that French characters are the same as their English equivalent.

For example, "Bélanger" should compare equal to "Belanger". Or "Coût" compares equial to "Cout".

I used to use CString1.Collate(CString2) in an older version of MS Visual Studio C++, but it no longer seems to work.
0
Comment
Question by:DickStone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 1000 total points
ID: 34114359
According to the help files this should work.

//typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;
setlocale(LC_ALL,"german");

CAtlString str1 = _T("strasse");
CAtlString str2 = _T("straße");

int n;

n = str1.Collate(str2);
_ASSERT(n == 0);

// Comparison is a strict ASCII comparison with no language rules.
n = str1.Compare(str2);

_ASSERT(n < 0);


How did you do it before - that doesn't work now.  (OP system changes?  Visual Studio version changes ?)

Open in new window

0
 

Author Comment

by:DickStone
ID: 34115939
I didn't need setlocale(LC_ALL,"French") before.I also didn't need CAtlString before.

I just tried turning on setlocale. It appears to screw up lots of other stuff -- even to the point of causing an infinite loop. It doesn't seem to be a solution to making "Bélanger"and "Belanger" equivalent.

It appears that Collate worked before, but no longer does without it, though.

Any good ideas? Maybe I should write a CollateNoFrench() that replaces the French characters before calling Collate?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 1000 total points
ID: 34118299
I just lookaed at setlocale in help.
There is a setting LC_COLLATE (instead of LC_ALL) that might be suitable.

Also you should only require the change during your comparision - so:

setlocale(LC_COLLATE, "French");
//compare the strings
setlocale(LC_COLLATE, "");    //Sets the locale to the default, which is the user-default ANSI code page obtained from the operating system.


0
 

Author Comment

by:DickStone
ID: 34124137
The good news is that it this works!

The bad news is that it's about 5 times as slow as converting strings (change "é" to "e", and "û" to "ut" and etc.) and then doing a normal Compare. I wrote a little function to do this.

Of course, the speed isn't your fault -- your answer is great  and I'll use it in the future when I'm not doing about 10,000 compares (as in this particular case).

)
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34124891
:-)

Thanks for the feedback re performance.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question