PDA

View Full Version : Alphabetizing a string array?


dwalden74
01-02-2003, 05:11 PM
Anyone know how to alphabetize a string array?
For example, if the array consists of the strings

baboons
cobras
apes

the alphabetized array would be

apes
baboons
cobras


:beer:
David

Nicool
01-02-2003, 06:19 PM
I hope for you their already exists a function in Maya mel :hmm:

dwalden74
01-02-2003, 06:38 PM
None that I´ve seen, that´s why I asked.

:beer:

bigfatMELon
01-02-2003, 07:08 PM
Oh, but there is. It's the sort command. Example:


string $array[] = {"Fili", "Dwalin", "Balin", "Kili"};
print `sort $array`;

Balin
Dwalin
Fili
Kili


-jl

dwalden74
01-03-2003, 09:34 AM
hey that´s great, thanks! :beer: I was looking through the other string commands (ie, stringArrayRemoveDuplicates), but sadly there were no "related commands" like this listed...

You is one big fat melon!
David

bigfatMELon
01-03-2003, 11:01 PM
Depends on where you look. See ArrayTools (my version, not the imposterized version someone else wrote with the same name) in highend3d.

//Examples:
// $fatArray = {"blue", "blue", "red", "green", "blue", "green"};
// flattenStringArray $fatArray;
// // Result: blue red green //

-jl

dwalden74
01-04-2003, 08:45 AM
No, I mean I was looking through the MEL docs.

See ArrayTools (my version, not the imposterized version someone else wrote with the same name) in highend3d.

Some of these seem to do the same thing as some standard Maya commands:

addStringArray -> stringArrayCatenate
flattenStringArray -> stringArrayRemoveDuplicates

Also itemInStringArray could be used like stringArrayCount (the latter returns number of occurences in a string of an item)

The others seem pretty cool.

:beer:
David

bigfatMELon
01-04-2003, 09:13 AM
This is true. I wrote these long ago, long before those commands were available. Not that it matters who wrote them first, but that is the reason they appear in the set.

You might also take a look at StringTools, a large set of wrappers for regex and more complex string functions.

-jl

dwalden74
01-04-2003, 10:38 AM
yo´, thanks for the tip.

david

CGTalk Moderation
01-14-2006, 02:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.