Solved

String compare on non-English names?

Posted on 2010-11-11
5
468 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
source code to scan multiple images 6 91
My project did see openJDK that I installed. What could be the problem 7 143
Not needed 13 112
Message not shown 5 50
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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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