Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Sort Tarray of FStrings Alphanumericaly

I have a TArray of FStrings that I would like to sort Alphanumerically. And I know TArray has a sort function which relies on predicates which Im not really familiar with. How would I go about sorting this array?

Product Version: Not Selected
more ▼

asked Jan 02 '15 at 02:24 PM in C++ Programming

avatar image

264 21 17 139

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

TArray.Sort() has two overloads. The first one doesn't take and arguments, so you can just call MyStringArray.Sort() and it will sort alphanumerically, no predicate logic required.

more ▼

answered Jan 02 '15 at 05:53 PM

avatar image

Jared Therriault
399 26 22 52

avatar image Opamp77 Jan 03 '15 at 04:04 PM

Thanks, I never noticed that.

avatar image BrɑκеPɑd STAFF Jan 05 '15 at 04:42 PM

Just to add to this, if you wanted to define any custom sorting logic, you could do so by passing a lambda to the sort:

 // Sort the array in alphanumeric descending order.
 // The predicate should return true if One should be sorted before Two, false otherwise
 MyArray.Sort([](const FString& One, const FString& Two){
     return One > Two;

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

If you want to sort it by yourself you could just go through the array with a loop and check which string is smaller with the normal comparison operator. Every kind of sorting algorithm should work.

Don't have time testing this at the moment.

more ▼

answered Jan 02 '15 at 03:00 PM

avatar image

6.8k 333 185 470

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question