Solved

String compare on non-English names?

Posted on 2010-11-11
5
467 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
  • 3
  • 2
5 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 250 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
Looking for a specific application/software 2 104
withoutTen challenge 14 97
Annoying "thing" blocks my view 4 80
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. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now