ID:156095
 
Ok, I know how to sort a list and all that but now I've ran into a little problem. I have a datum called person. I also have a list of all the persons in the world. Now I'd need to sort the persons list by the person.name.


I really hope that someone understood. I've never wrote a more confusing text IMO.
Sounds like you want to sort your list alphabetically. You can do this the same way you would sort a list of numbers. However, if you want to avoid capitalization issues, you should compare letters through the lowertext proc.
In response to Spunky_Girl
Thanks. I had tried different sorting libraries but didn't find a good one. I began to search deeper and finally found a working one.
In response to Spunky_Girl
Keep in mind, he will have to loop through every single letter in each word to do this properly. He would also need to convert each letter to an ascii character.

Also, if the list size isn't extensively large, my sorting demo might be of use.
In response to CauTi0N
From what people like Garthor and Kaioken have told me, you do not have to convert any letters to ascii.
if("a" > "A")
world<<"a"
else world<<"A"
//should display a
In response to Spunky_Girl
Really? Wow, I never knew that - I was told a while back it was required. In any case, every letter would still need to be checked.
In response to CauTi0N
Which is still less than converting all the letters to ascii and then comparing ;P

Uppercase has a lower value than lowercase, and z is the highest, where a is the lowest. You can exploit that system wherever you see fit :D

EDIT
And besides... I think you would only need to compare more than the first letter of every word, only if two entries in the list have the same first letter.
In response to Spunky_Girl
Spunky_Girl wrote:
EDIT
And besides... I think you would only need to compare more than the first letter of every word, only if two entries in the list have the same first letter.

Yes, naturally. If it recognizes the first letters are different, it should automatically switch and move on. :)
In response to CauTi0N
Then it wouldn't be so horribly inefficient as I seem to think you were implying.
In response to Spunky_Girl
Exactly. :)
In response to CauTi0N
Then... What was the issue? :\
In response to Spunky_Girl
I honestly kind of lost my train of thought - I don't have any issue.

Galactic Soldier: I don't think she intended to look through each letter against any type of constant. It was just an example.
sorttext does not return a list of sorted text values. It returns a number indicating HOW the list is sorted, if it is sorted. Perhaps you should be the one to read the guide, if not the topic of this thread?

@CauTi0N:
Yes, it was just an example to illustrate the... letter precedence (for lack of the actual term x.x)... that DM uses.
Yes, it uses less resources to alphabetize using sorttext/sorttextEx than to loop through all the letters. I knew this already. But I have to ask, why are you challenging my knowledge of DM all of the sudden when all I did was mention that CauTi0N was wrong when he said we had to convert letters to ascii in order to sort them, and then further illustrated how DM handles... letter precedence (again, for lack of the actual term x.x)?

So I have to ask again... Perhaps you should read the topic of this thread? I believe your mention of utilizing and implementing sorttext/sorttextEx belong in a response to the OP, rather than to me or CauTi0N, since the OP is the one who needs help with the actual sorting. CauTi0N and I were talking about something different than the actual implementation of sorting text.
Then maybe you should talk more about that with the OP than with CauTi0N or myself.
In response to CauTi0N
CauTi0N wrote:
Really? Wow, I never knew that - I was told a while back it was required. In any case, every letter would still need to be checked.

Why would you think that? BYOND makes no distinction between chars and strings, so there's no difference between comparing "a" and "A" or "apple" and "Apple". The < and > operators work just fine on strings of any length.
In response to Garthor
I didn't realize that the operators would check them that way - I was told by someone back when Chat was frequented that those operators were for numerical values. I never read this section, which I just realized.

As for the second part of that statement: Wouldn't a comparison between "apple" and "abs" require a check between each letter (in this case, up until the second letter), in order to maintain correct alphabetization?
In response to CauTi0N
How so?
client/verb/test()
if("apple" > "abs")
world<<"apple"
//displays apple o.O