0

Alphabetically sorting

Hello, I have problem with sorting alphabetical. For instance we have string array with variables "SC Freiburg", "SV Darmstadt", "Schalke". I'd like to get sorted array like this: "SC Freiburg", "Schalke", "SV Darmstadt"

29th Jul 2025, 5:24 PM
TeaserCode
3 Respuestas
+ 5
Based on your example, you wish for the sort to be case-insensitive (e.g., 'C'=='c', and . 'c'<'V') It is a little tricky, but it looks like you have the necessary skills. To do that, you can write a custom compare routine and pass the function into the sort function (std::sort()) as the third argument. Your comparator should take two string parameters. It would convert the comparison strings to all uppercase or all lowercase before comparing. It should then return a bool that indicates whether the first argument should go before the second argument in the desired sorted order. Sort() handles the rest, calling your comparator whenever it needs to choose which string comes before the other.
29th Jul 2025, 5:42 PM
Brian
Brian - avatar
0
So you have do this for every combination? Or how? And what is if you use these(ß,ś,ī etc….)?
29th Jul 2025, 7:52 PM
PythonJosh
PythonJosh - avatar
0
PythonJosh sorry, I am inexperienced with the lexicographical order of wide characters. Look into using the C++ library routines that are named with the 'W' prefix (indicating the Wide char version).
31st Jul 2025, 3:24 PM
Brian
Brian - avatar