Sorting an array of strings in C ++ regardless of "A" or "a" and using å, ä ö?

How do you sort an array of strings in C ++ so that this happens in the following order:

mr Anka

Mr broWn

mr ceaser

mR donK

mr ålish

Mr Ätt

mr önD

//following not the way to get that order regardeless upper or lowercase and å, ä, ö
//in forloop... 
string handle;
point1 = array1[j].find_first_of(' ');
string forename1(array1[j].substr(0, (point1)));
string aftername1(array1[j].substr(point1 + 1));
point2 = array1[j+1].find_first_of(' ');
string forename2(array1[j+1].substr(0, (point2)));
string aftername2(array1[j+1].substr(point2 + 1));
if(aftername1 > aftername2){
    handle = array1[j];
    array1[j] = array1[j+1];
    array1[j+1] = handle;//swapping
}
if(aftername1 == aftername2){
    if(forname1 > forname2){
        handle = array1[j];
        array1[j] = array1[j+1];
        array1[j+1] = handle;   
    }
}
+5
source share
3 answers

Tables and conversions.

First, I would convert the string to any of uppercase or lowercase letters:

#include <cctype>
#include <algorithm>
#include <string>

std::string test_string("mR BroWn");
std::transform(test_string.begin(), test_string.end(),
               test_string.begin(),
               std::tolower);

Then I will check for exceptions or use the equivalence table. If the character in question is in an array of exception characters, then use the equivalence table.

0
source

Unicode , . . , "IJ" . Unicode , : Unicode: http://site.icu-project.org/

std::sort ICU.

+6

stricoll , , . , , .

0

All Articles