Sorting a string array in C++ no matter of A or a and with å, ä ö?
- by Chris_45
How do you sort an array of strings in C++ that will make this happen in this 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;
}
}