Array.sortOn(String.length)?

Very simple test to do the sortOn method using the length
property of the strings, which doesn't seem to do anything.
this.words = ["abc","a","bc","ab"];
trace(this.words);
this.words.sortOn("length", Array.NUMERIC);
trace(this.words);
//TRACE REULTS
abc,a,bc,ab
abc,a,bc,ab
I found a couple of examples that use the y property of
MovieClips to sortOn, which appear to work.
http://labs.bigspaceship.com/2007/10/16/array-sorting/
http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=2
Any ideas?

I believe this is a bug. You might use this fix:

Similar Messages

  • How to delete first few characters from all the elements of an array of strings

    hi
    I have a 2-dimensional array of strings length 104. I have to delete first 6 characters from all the elements of array and then change the strings to int. how to do it?? plz help

    Attached you can find the screenshot showing how to do so.
    Bye!
    Licia
    Attachments:
    array.jpg ‏14 KB

  • Length of double dimensional array of string type

    I have this double dimensional array.
    String sArray[][] =
    {"0,0","0,1","0,2","0,3"},
    {"1,0","1,1","1,2","1,3"},
    {"2,0","2,1","2,2","2,3"},
    {"3,0","3,1","3,2","3,3"}
    How to find the length of this?
    thanks
    MS

    There's two different lengths... The number of rows, you could say... and the number of fields in each row.
    sArray.length;
    or for a particular row...
    int row = 0;
    sArray[row].length;

  • "Using a CIN to Create an Array of Strings in LabVIEW" example crashes LV on Linux

    Tried to utilize this NI example: "Using a CIN to Create an Array of Strings in LabVIEW" (http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B4B282BE7EF907C8E034080020E74861&p_node=&p_source=External)
    Compiles OK with the makefile made by the LV's lvmkmf utility. Nevertheless when I try to run the VI (with the code loaded into the CIN, of course), LabVIEW 7.1.1 on a SUSE 9.3 Linux machine crashes:
    LabVIEW caught fatal signal
    7.1.1 - Received SIGSEGV
    Reason: address not mapped to object
    Attempt to reference address: 0x0
    Segmentation fault
    Any ideas? Did anybody try this on a Windows machine?

    H View Labs wrote:
    Tried to utilize this NI example: "Using a CIN to Create an Array of Strings in LabVIEW" (http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B4B282BE7EF907C8E034080020E74861&p_node=&p_source=External)
    Compiles OK with the makefile made by the LV's lvmkmf utility. Nevertheless when I try to run the VI (with the code loaded into the CIN, of course), LabVIEW 7.1.1 on a SUSE 9.3 Linux machine crashes:
    LabVIEW caught fatal signal
    7.1.1 - Received SIGSEGV
    Reason: address not mapped to object
    Attempt to reference address: 0x0
    Segmentation fault
    Any ideas? Did anybody try this on a Windows machine?
    This code is badly broken. In addition to resizing the actual handle to hold the number of string handles you also would need to create the string handles itself before attempting to write into them. NumericArrayResize is the fucntion to use as it will either resize an existing handle (if any) or create a new one if the value is uninitialized (NULL).
    /* resize strarr to hold handles to NUMSTRINGS strings */
    err = SetCINArraySize((UHandle)strarr, 0, NUMSTRINGS);
    if (err)
    goto out;
    /* perform this loop once for each element */
    /* of array of strings being created */
    for (i = 0; i < NUMSTRINGS;) {
    LStrHandle handle = (*strarr)->arg1[i];
    /* determine length of string that will be element of strarr */
    strsize = StrLen(str[i]);
    err = NumericArrayResize(uB, 1, &handle, strsize);
    if (err)
    goto out;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /* moves strsize bytes from the address pointed to */
    /* by str[i] to the address pointed to by the data pointer in the handle */
    MoveBlock(str[i], LStrBuf(*handle), strsize);
    /* manually set size of string pointed to by *strarr */
    (*((*strarr)->arg1[i]))->cnt = strsize;
    /* manually set dimSize of strarr */
    (*strarr)->dimSize = ++i;
    return noErr;
    out:
    return err;
    Rolf KalbermatterMessage Edited by rolfk on 06-30-2005 03:15 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Covert String Array to String

    Hey,
    I have this code that take a string
    EX:
    Straw? No, too stupid a fad, I put soot on warts
    and takes out the "?" and "," and places a space in their spot, then tokenizes the string so now all the spaces are gone (right?) then places the tokenized string into and array. Now I want that array into a string.
    Pretty much what I want to go from is
    this:
    Straw? No, too stupid a fad, I put soot on warts
    to:
    StrawNotoostupidafadIputsootonwarts
    here is my code
    import java.util.*;
    public class TrivialApplication {
         public static void main(String args[])
              System.out.println( "Hello World!\n" );
              String hello = "Straw? No, too stupid a fad, I put soot on warts";
              hello = hello.replace('?',' ');
              hello = hello.replace(',',' ');
              StringTokenizer tokenizer = new StringTokenizer(hello);
              String[] array = new String[hello.length()];
              System.out.println(tokenizer.countTokens());
              System.out.println(hello.length());
              int count = tokenizer.countTokens();
              int x = 0;
              while(tokenizer.hasMoreTokens())
                   array[x] = tokenizer.nextToken();
                   x++;
    }

    Sweet thanks man here is the finished code. I took out the array because it was now not needed.
    import java.util.*;
    public class TrivialApplication {
         public static void main(String args[])
              System.out.println( "Hello World!\n" );
              String hello = "Straw? No, too stupid a fad, I put soot on warts";
              System.out.println(hello + "\n");
              hello = hello.replace('?',' ');
              hello = hello.replace(',',' ');
              StringTokenizer tokenizer = new StringTokenizer(hello);
              StringBuffer buffer = new StringBuffer();
              int count = tokenizer.countTokens();
              while(tokenizer.hasMoreTokens())
                   buffer = buffer.append(tokenizer.nextToken());     
              hello = buffer.toString();
              System.out.println("New String with changes \n");
              System.out.println(hello);
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Replacing words in an array of strings

    hi
    im trying to create a method that takes three arrays of strings as parameters and replaces some words in one of them
    heres my code
    class A0
    public static void main (String[] args)
    int index;
    String[] in = {"life","is","a","bowl","of","pits"};
    String[] what={"pits", "bowl"};
    String[] with={"chocolates", "box"};
    String[] result=new String [in.length];
    result=findAndReplace(in, what, with);
    for (index=0;index<in.length;index++)
    System.out.print(result[index]+" ");
    static String[] findAndReplace (String[] in, String[] what, String[] with)
    int index1;
    int index2;
    String[] newString= new String [in.length];
    for (index1=0;index1<in.length;index1++)
    for (index2=0;index2<what.length;index2++)
    if (in[index1]==what[index2])
    newString[index1]=with[index2];
    else
    newString[index1]=in[index1];
    return newString;
    ok so it's supposed to print life is a box of chocolates, only it prints life is a box of pits???pls help

    i figured it out

  • Cast Object Array to String Array.

    When I try to cast an object array to string array an exception is thrown. How do I go about doing it?
    Vector temp = new Vector();
    Object[] array = temp.toArray();
    String[] nonterms;                              
    nonterms = (String[])array;
    Thanks,
    Ally

    Try this
    import java.util.Vector;
    public class Test
         public static void main(String args[]) throws Exception
              Vector v = new Vector();
              v.add("a");
              v.add("b");
              v.add("c");
              Object[] terms = v.toArray();
              for(int i = 0; i < terms.length; i++)
                   System.out.println((String)terms);
    Raghu

  • Trying to 'simulate' an array of strings

    In pseudo-code what I would like to do is this:
    Array[x][3]
    Array[1][1] = "First"
    Array[1][2] = "Data1"
    Array[1][3] = true
    Array[2][1] = "Second"
    Array[2][2] = "Data2"
    Array[2][3] = false
    counter = 1
    while(counter < 3) {
    print Array[counter][1]
    counter++
    In Java-think I created a class of data, and wanted to create a series of elements (array) of this class. But, suprise, my code snippit below doesn't work....
    class DataSaved {
    String InputName;
    String InputValue;
    boolean IsHidden;
    public class test {
    public static void main(String [] args) {
    DataSaved dataum;
    int counter = 0;
    dataum = (DataSaved) DataSaved.firstElement();
    dataum.addElement("first","1data",true);
    dataum.addElement("second","2data",true);
    dataum.addElement("third","3data",true);
    dataum.addElement("xxxfirst","4data",true);
    dataum.addElement("fxxirst","5data",true);
    dataum.addElement("sixfirst","6data",true);
    dataum.addElement("7first","7data",true);
    dataum.addElement("8first","8data",true);
    dataum.addElement("9first","9data",true);
    // move to the top element
    datum.firstElement();
    while (counter < 6 ){
    System.out.println(dataum.nextElement());
    counter++;
    So....what am I not understanding, and how can I make this snippit work?

    Great, now your DataSaved class is correct.
    The next step is how to deal with arrays.
    Suppose you have an array of Strings. Here's how it looks like:
    String[] myArray;Before you can use it, you have to actually occupy the space it needs. (Arrays are objects in Java, so basically, but sloppily speaking, you have to instantiate an "array class"):
    myArray = new String[15];The length of the arrays in Java is constant. You have to tell the length during construction time, and you won't be able to change it later.
    Also, if you create an array as above, each of the elements will contain null (were it an array of primitive types, it would contain the appropriate version of zero for that primitive type). Therefore, you have to load the elements one by one:
    myArray[0] = new String("first string");
    myArray[1] = new String("second string");
    myArray[14] = new String("last string");As you see, indexing starts with zero. I also have to note, that "new String(...)" is an unnecessary and in most cases poor programming technic, the string constants would do in this case (but not if the array is not an array of strings but array of some kind of objects).
    Another note. It's usually a bad programming technic to reach the fields of another class. Sometimes we do, but only when we have good reason. It's better if you provide setXXX and getXXX methods, and let your fields to have private access:
    class DataSaved {
       // your current code appears here
       public void setInputName(String name) {
          InputName = name;
       public String getInputName() {
          return InputName;
    }Now, your cycle which retrieves the values should look something like this:
    for (int cntr=0;  cntr<myArray.length;  cntr++) {
       System.out.println(myArray[cntr].getInputName());
    }That myArray.length is an attribute of the arrays, which tells you the length of the array. Now, if you have to change the length later, you don't have to scrutinize your code, since the "magic number" appears in the code exactly once.
    You may read about the arrays and how they're handled in Java here:
    http://java.sun.com/docs/books/tutorial/java/data/arrays.html
    That ArrayList is another story; if you have succeeded with your array, come back and ask. "Preview": ArrayList is a way how to deal with arrays which might be expanded and shrunk as needed.
    You also might consider reading the tutorial about the collections (perhaps in a later time):
    http://java.sun.com/docs/books/tutorial/collections/index.html

  • How to shrink an array of strings

    I am working on the method shift() which is similar to the one found in Perl. This method will take an array of strings and return the first string in the array. The resulting array should shrink by one element.
    However, I am having trouble with getting the array modified.
    I will show the output and the code.
    java DemoShift a b c
    Args len: 3 Argument #0: a
    bcc
    Args len: 3 Argument #1: b
    ccc
    Args len: 3 Argument #2: c
    ccc
    As you can see, I expect the array to get smaller each time, but I was unsuccessful. I have tried the following approaches:
    1. Convert the array of strings into StringBuffer by using append() and adding some delimeter, and then then using toString().split()
    2. Use ArrayList class to change the array length
    3. System.arraycopy.
    Here is the code. Let me know what do I need to get the array "args" get shrinked every time.
    <pre>
    import java.util.*;
    import java.io.*;
    class DemoShift
        public static void main(String args[])
            for (int counter = 0; counter < args.length ; counter++)
                System.out.println("Args len: " + args.length + " Argument #" + counter + ": " + shift(args));
                for (String st:args) System.out.print (st);
                System.out.println();
        public static String shift(String... args)
            StringBuilder sb = new StringBuilder(args.length-1);
            String firstString = args[0];
            String temp[] = new String[args.length -1];
            for (int counter = 1; counter < args.length; counter++)                                             
                sb.append(args[counter]);                                                                       
                sb.append("MYSPLIT");                                                                           
            temp = sb.toString().split("MYSPLIT");                                                              
            System.arraycopy(temp, 0, args, 0, temp.length);
            return firstString;
        }Edited by: vadimsf on Oct 25, 2007 10:17 PM

    I didn't really pay much attention to your problem, but will this help?
         public static void main(String[] args) {
              String[] test = {"test1", "test2", "test3"};
              for (String s : shift(test))
                   System.out.println(s);
         public static String[] shift(String[] arr)
              String[] a = new String[arr.length - 1];
              for (int i = 1; i < arr.length; i++)
                   a[i - 1] = arr;
              return a;

  • Not using an array of strings

    how do I write a java method without using an array of strings?
    for example:
    import java.io.File;
    public class rename
    public static void main(String[] args)
    File src = new File(args[0]);
    File dst = new File("c:\\temp\\temp.txt");
    boolean wasRenamed = src.renameTo(dst);
    I don't want to have main use an array of strings but I want rename to work as a class

    This is what I changed it to and am getting an -- Exception in thread "main" java.lang.NoSuchMethodError: main
    Sorry this is my first java program
    import java.io.File;
    class App {
         private App() {
              super();
         static final public void main(final String[] args) {
              switch (args.length) {
                   case 1:
                        try {
                             Rename rename = new Rename();
                             rename.rename("c:\\felss\\charles.txt.bak"); // see, it's kind of silly to have same names for class and method
                             System.exit(0);
                        catch (Throwable e) {
                             e.printStackTrace();
                             System.exit(1);
                        break;
                   default:
                        System.err.println("Usage: java App [new name]");
                        System.exit(1);
    public class Rename {
         public Rename() {
              super();
         final public void rename(final String newName) {
              File src = new File(newName);
              File dst = new File("c:\\felss\\charles.txt");
              boolean done = src.renameTo(dst);
    }

  • Forwarding array of String to jsp

    Hi all
    I want to forward an array of string to jsp page. I use the following code:
    servlet:
    request.setAttribute("list", list);and
    jsp:
    <%  String[] symptomslist = (String[])request.getAttribute("symptomslist"); %>But the values in the array are null. The length is correct. Can anyone please help me in this?
    Thanks a lot.
    dude

    Hey Hey,
    Sorry,
    My code was suppose to be this:
    String[] list = (String[])request.getAttribute("list");Thanks for noticing. Can anyone still help me?
    dude

  • Converting Array of string to an array of integers

    I have a problem converting a array of string to array of int's
    This is my code...
    String[] forminfo = request.getParameterValues("forsendur");
          int[] forminfoInt = Integer.parseInt(forminfo); This is the error message:
    Incompatible type for method. Can't convert java.lang.String[] to java.lang.String.
                          int[] forminfoInt = Integer.parseInt(forminfo);
                                                               ^can anyone help me with this?

    ParesIn methos returns a int buto not a int[]. You must iterate along the String array and perform the methos for each element setting the return value into the element of the int array
    Ej:
    int[] intArray = new int[stringArray.length]
    for(int i = 0; i < stringArray.length; i++)
    intArray[i] = Integer.parseInt(stringArray);

  • Would like some help converting an array of strings into multiple parsed string arrays

    Hello everyone.
    this is a very novice question and I sincerely apologize for that, but i need some direction!
    i have an array of strings:
    (('J01',), ('0', '0', '0', '1'))
    (('J02',), ('0', '1', '0', '1'))
    (('J03',), ('0', '0', '0', '0'))
    ect...
    i would like to know what are some of the best ways to gain access to this information (aka, parse it). The field lengths are not static and all those ones and zeros could very possibly be two digits at times (0 = off state, 1-100 = on state), so simply pulling characters out of a given position of the string will not always work.
    what i would like to achieve is to make either separate arrays for each desirable element, eg:
    array one:
    J01
    J02
    J03
    array two:
    0
    0
    0
    array three:
    0
    1
    0
    and so on.
    or maybe even a matrix (if that’s feasible).
    other than that I am totally up for suggestions!!
    thank you very much,
    Grant.

    Assuming fixed structure (not necessarily length of the different numbers or names).

  • Array of String ?

    Hi everybody,
    Could anybody help me this( I finished step 1 and step 2, but not step 3 )
    Step1: I type a whole string when i were asked by computer:
    "I am a new student of Java programming"
    Step 2: I want to break this sentence into words as: "I", "am", "a", "new", "student"...
    Step 3: And then, I want to store these words into an array of string. But I do not know how?
    Here is my codes:
    // Step1
    String wholeString = keyboard.readLine();
    // Step2:
    StringTokenizer myString = new StringTokenizer(wholeString, " ");
    String[] mySubStrings = new String[myString.countTokens()];
    for(int i =0; myString.hasMoreTokens(); i++)
    mySubStrings[i] = new String(myString.nextToken());
    for(int j = 0; j< mySubStrings.length; j++)
    System.out.println(" " + mySubStrings[j]);
    // Step 3 (Could any body help me. I tried it many times, but i got errors !)
    Thank you very much in advance. I appreciate.
    still_learn

    Thank you very much, danperkins. Actually i missed typing.
    But could you or anybody help me do step 3 ? OK I made it more briefly and simply like this:
    I have 5 strings: "I", "am", "a","new", "student".
    How can i store them into array of string as "
    String[] myStorage = {"I", "am", "a", "new", "student"};
    How could i do that?
    Thank you very much.
    still_learn

  • Help Sorting array of strings with numbers in them

    Hello I need to sort an array of Strings of numbers. The order is not what I want it to be. instead of 1, 5, 20 it will go 1, 20, 5.
    I did a google search for this and found some code that could fix this. The only problem is I tried using it as a method in my program and am getting a compile-time error that I'm not sure how to fix.
    C:\Documents and Settings\Owner\Desktop\stringcompare.java:18: '(' or '[' expected
                new Comparator<String>()
                                    ^I'm not sure what to do here. Any help would appreciated.

    import java.io.*;
    class MyProgram{
    //This is my old bubble sort method which screws up with numbers
    public static String[] sort( String[] points)
              boolean keepGoing = true;
              while(keepGoing == true){
                   keepGoing = false;
                   for(int i = 0; i < points.length - 1; i ++)
                        if(points.compareToIgnoreCase(points[i + 1]) < 0)
                             String temp = points[i];
                             points[i] = points[i + 1];
                             points[i + 1] = temp;
                             keepGoing = true;
              return points;
    //This method reads a pre-existing text file
    public static String[] readPoints() throws IOException
              FileReader file = new FileReader("points.txt");     
              BufferedReader in = new BufferedReader(file);
              String temp;                
              String[] list = new String[100];     
              int i = 0;
              while (i < list.length)                    
                   temp = in.readLine();
                   if (temp != null)
                        list[i] = temp;                    
                   else
                        list[i] = " ";
                   i++;
              in.close();                              
              return list;
    //rewrites file after being sorted
         public static void savePoints(String[] points) throws IOException
              FileWriter file = new FileWriter("points.txt");
              BufferedWriter out = new BufferedWriter(file);
              int i = 0;
              while (i < points.length)          // while the end of file is not reached
                   out.write(points[i]) ;
                   out.newLine();
                   i++;
              out.flush();
              out.close();
    public static void main(String[]args) throws Exception{
    String[]points = new String [100];
    points = readPoints();
    points = sort(points);
    savePoints(points);
    for(int i = 0; i < points.length - 1; i++)
    System.out.println(points[i]);
    The problem is that it doesn't sort as I would like it and I'm not sure how to get the comparator to work properly.
    Edited by: myol on May 31, 2008 4:21 PM
    Edited by: myol on May 31, 2008 4:23 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for