if you are a human please do not click here
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
Username :
Password :
Home
Help
Calendar
Register
Login
XMetaL Community Forums
»
General
»
General XMetaL Discussion
»
Array sorting
Pages:
1
« previous
next »
Print
Author
Topic: Array sorting (Read 2263 times)
WOB
Member
Posts: 4
Array sorting
«
on:
February 15, 2010, 04:59:02 PM »
What code do I need to include that will allow me to use the java Arrays.sort command?
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member
Posts: 1548
Re: Array sorting
«
Reply #1 on:
February 15, 2010, 05:26:43 PM »
We need more information to help with this (unless another forum user can guess at what you are trying to do).
Logged
WOB
Member
Posts: 4
Re: Array sorting
«
Reply #2 on:
February 17, 2010, 09:03:11 AM »
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.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member
Posts: 1548
Re: Array sorting
«
Reply #3 on:
February 19, 2010, 06:09:17 PM »
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?
Logged
WOB
Member
Posts: 4
Re: Array sorting
«
Reply #4 on:
February 22, 2010, 08:01:58 AM »
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.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member
Posts: 1548
Re: Array sorting
«
Reply #5 on:
February 22, 2010, 03:23:31 PM »
Am I confusing Java with JavaScript?
Or are you really using Java?
Logged
WOB
Member
Posts: 4
Re: Array sorting
«
Reply #6 on:
February 22, 2010, 03:25:04 PM »
Sorry, it is defined in the macro as JScript
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member
Posts: 1548
Re: Array sorting
«
Reply #7 on:
February 22, 2010, 03:31:05 PM »
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);
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member
Posts: 1548
Re: Array sorting
«
Reply #8 on:
February 22, 2010, 03:38:34 PM »
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
«
Last Edit: February 22, 2010, 06:11:50 PM by Derek Read
»
Logged
magnusirvson
Member
Posts: 1
Re: Array sorting
«
Reply #9 on:
March 12, 2010, 04:11:29 PM »
Did you determine if this was an accurate solution?
Logged
Pages:
1
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> Forum Information
=> General XMetaL Discussion
=> DITA and XMetaL Discussion
=> XMetaL Tips and Tricks
=> XMetaL Announcements and Events
Loading...