Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

String compare on non-English names?

Posted on 2010-11-11
5
Medium Priority
?
487 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 45

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 45

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 45

Expert Comment

by:AndyAinscow
ID: 34124891
:-)

Thanks for the feedback re performance.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

598 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