General XMetaL Discussion

  • WOB

    Array sorting

    Participants 8
    Replies 9
    Last Activity 12 years, 4 months ago

    What code do I need to include that will allow me to use the java Arrays.sort command?

    Reply

    Derek Read

    Reply to: Array sorting

    We need more information to help with this (unless another forum user can guess at what you are trying to do).

    Reply

    WOB

    Reply to: Array sorting

    I am storing attribute values for an attribute named “Target” in an array. I want to then sort the values so that I can look for duplicate ones. The next step will be to notify the user where in the document there are duplicates so that they can correct them. The Target attribute values are used for Cross References.

    Reply

    Derek Read

    Reply to: Array sorting

    Does one of the following help?

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html
    http://www.java2s.com/Tutorial/Java/0140__Collections/SortingArrays.htm

    Sorting in Java should be pretty straightforward once you have an array declared and populated. Or am I missing something?

    Reply

    WOB

    Reply to: Array sorting

    I could write a simple sort myself. However, I was hoping to take advantage of a Java sort command. But when I use this line of code: “Arrays.sort(sortTVals);” then the macro hangs. sortTVals is defined as an array using the statement: “var sortTVals = new Array();”.  In my test the array has 4 values in it that I can display. However, the macro never continues executing beyond the sort command.

    Reply

    Derek Read

    Reply to: Array sorting

    Am I confusing Java with JavaScript?
    Or are you really using Java?

    Reply

    WOB

    Reply to: Array sorting

    Sorry, it is defined in the macro as JScript

    Reply

    Derek Read

    Reply to: Array sorting

    Here's the simplest JScript example I can think of, and it works for me:

    [code]//XMetaL Script Language JScript:
    var a1 = new Array(“foo”,”bar”,”baz”,”2″,”1″,”1000″);
    Application.Alert(“Original: ” + a1);
    a1.sort();
    Application.Alert(“Sorted: ” + a1);[/code]

    Reply

    Derek Read

    Reply to: Array sorting

    You might also find this JScript prototype function useful for your specific need:
    http://www.martienus.com/code/javascript-remove-duplicates-from-array.html

    …and the Microsoft documentation on the JScript sort method is here:
    http://msdn.microsoft.com/en-us/library/4b4fbfhk%28VS.85%29.aspx

    Reply

    magnusirvson

    Reply to: Array sorting

    Did you determine if this was an accurate solution?

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support