listNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
list << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec" << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec" << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec";
int startSize = list.size();
int num;
for(int i = 0; i<startSize; i++){
for(int j = 0; j<listNames.size(); j++){
if(list.contains(listNames[j],Qt::CaseInsensitive)){
num = list.indexOf(listNames[j]);
//cout << num << endl;
}
}
tempList << list[num];
list.removeAt(num);
}
for(int i = 0; i<startSize; i++){
list << tempList[tempList.size()-1];
tempList.removeLast();
}
for(int i = 0; i<list.size(); i++){
cout << list[i].toStdString() << endl;
}
QStringList listNames;
QStringList list;
QStringList tempList;
listNames << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
list << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec" << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec" << "Jan" << "Mar" << "May" << "Jul" << "Sep" << "Nov" << "Feb" << "Apr" << "Jun" << "Aug" << "Oct" << "Dec";
int startSize = list.size();
int num;
for(int i = 0; i<startSize; i++){
for(int j = 0; j<listNames.size(); j++){
if(list.contains(listNames[j],Qt::CaseInsensitive)){
num = list.indexOf(listNames[j]);
//cout << num << endl;
}
}
tempList << list[num];
list.removeAt(num);
}
for(int i = 0; i<startSize; i++){
list << tempList[tempList.size()-1];
tempList.removeLast();
}
for(int i = 0; i<list.size(); i++){
cout << list[i].toStdString() << endl;
}
To copy to clipboard, switch view to plain text mode
in this example the user input would be the QStringList list and the order they are being sorted is QStringList listNames
it works perctly if the user inputs the same exact as the sorting order.
but what I would like to do is if the user inputs "jan" it will know it is the same as "Jan" I can check to see if it is the same by using contains which will yeah find it...but
when I do the index of it I will always get -1 because I can not think of a way to do
indexOf
(QString, Qt
::CaseInsensitive)
indexOf(QString, Qt::CaseInsensitive)
To copy to clipboard, switch view to plain text mode
is this even possible?
EDIT: well I can think of one way but I would prefer not to do it.
it would be to use QString::toUpper or QString::toLower for both of the QStringLists and it wouldnt matter what they input.
but the problem with that is.....I want the end result to be first letter Uppercase rest of the letters Lowercase
Bookmarks