Topic
  • 5 replies
  • Latest Post - ‏2016-08-01T18:38:37Z by DOORSHAM
SystemAdmin
SystemAdmin
3180 Posts

Pinned topic How to sort a string array string[]

‏2012-11-29T06:14:03Z |
Hello,

I need to sort a string[] array ... can any one give me a example how to do it??
Updated on 2012-11-30T00:11:57Z at 2012-11-30T00:11:57Z by Jagtattoo
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: How to sort a string array string[]

    ‏2012-11-29T06:31:57Z  
    Just go to the developer works forum, enter "sort string" into the search field and read the first entry that appears.
  • Jagtattoo
    Jagtattoo
    24 Posts

    Re: How to sort a string array string[]

    ‏2012-11-30T00:11:57Z  
    Once the string array is defined and populated, you can simply enter the command "sort <array name>". This will sort the entries in the array alphabetically. Good luck!!
  • SiddharthW
    SiddharthW
    1 Post

    Re: How to sort a string array string[]

    ‏2016-08-01T13:39:48Z  

    Hello

    I am trying to sort string array. But it fails to sort.  Please check the code below.

    string sSource[12] = {"LLRQ_LIBM_ACOSH__2", "LLRQ_LIBM_ACOSH__1", "LLRQ_LIBM_ACOSH__0", "LLRQ_LIBM_ACOSH__1", "LLRQ_LIBM_ACOSH__1",
    "LLRQ_LIBM___FPCLASSIFY_DOUBLE__1", "LLRQ_LIBM___FPCLASSIFY_DOUBLE __0", "LLRQ_LIBM_FERAISEEXCEPT__1", "LLRQ_LIBM_FERAISEEXCEPT__0", "LLRQ_LIBM_ACOS__1",
    "LLRQ_LIBM_ACOS__2", "LLRQ_LIBM_ACOS__0"}

     

    string LLRQ_list[12]

    int x
    for(x = 0; x <5 ; x++)
    {
        LLRQ_list[x] = sSource[x]

    }

    sort LLRQ_list
    for(x = 0; x <11 ; x++)
    {
        print LLRQ_list[x]"\n"
        //print sSource[x]"\n"

    }

    It fails with access voilation I am not able to get sorted array.  Please let me know whether I doing something wrong? Or I missed anything ?

  • Wolfgang Uhr
    Wolfgang Uhr
    339 Posts

    Re: How to sort a string array string[]

    ‏2016-08-01T14:06:13Z  

    Hello

    I am trying to sort string array. But it fails to sort.  Please check the code below.

    string sSource[12] = {"LLRQ_LIBM_ACOSH__2", "LLRQ_LIBM_ACOSH__1", "LLRQ_LIBM_ACOSH__0", "LLRQ_LIBM_ACOSH__1", "LLRQ_LIBM_ACOSH__1",
    "LLRQ_LIBM___FPCLASSIFY_DOUBLE__1", "LLRQ_LIBM___FPCLASSIFY_DOUBLE __0", "LLRQ_LIBM_FERAISEEXCEPT__1", "LLRQ_LIBM_FERAISEEXCEPT__0", "LLRQ_LIBM_ACOS__1",
    "LLRQ_LIBM_ACOS__2", "LLRQ_LIBM_ACOS__0"}

     

    string LLRQ_list[12]

    int x
    for(x = 0; x <5 ; x++)
    {
        LLRQ_list[x] = sSource[x]

    }

    sort LLRQ_list
    for(x = 0; x <11 ; x++)
    {
        print LLRQ_list[x]"\n"
        //print sSource[x]"\n"

    }

    It fails with access voilation I am not able to get sorted array.  Please let me know whether I doing something wrong? Or I missed anything ?

    Try:

    Skip skpSort = createString();

    put (skpSort, "string 1", "string 1");

    put (skpSort, "string 3", "string 3");

    put (skpSort, "string 2", "string 2");

    string sHelp;

    for sHelp in skpSort do {

      print sHelp "\n";

    }

  • DOORSHAM
    DOORSHAM
    189 Posts

    Re: How to sort a string array string[]

    ‏2016-08-01T18:38:37Z  

    Hello

    I am trying to sort string array. But it fails to sort.  Please check the code below.

    string sSource[12] = {"LLRQ_LIBM_ACOSH__2", "LLRQ_LIBM_ACOSH__1", "LLRQ_LIBM_ACOSH__0", "LLRQ_LIBM_ACOSH__1", "LLRQ_LIBM_ACOSH__1",
    "LLRQ_LIBM___FPCLASSIFY_DOUBLE__1", "LLRQ_LIBM___FPCLASSIFY_DOUBLE __0", "LLRQ_LIBM_FERAISEEXCEPT__1", "LLRQ_LIBM_FERAISEEXCEPT__0", "LLRQ_LIBM_ACOS__1",
    "LLRQ_LIBM_ACOS__2", "LLRQ_LIBM_ACOS__0"}

     

    string LLRQ_list[12]

    int x
    for(x = 0; x <5 ; x++)
    {
        LLRQ_list[x] = sSource[x]

    }

    sort LLRQ_list
    for(x = 0; x <11 ; x++)
    {
        print LLRQ_list[x]"\n"
        //print sSource[x]"\n"

    }

    It fails with access voilation I am not able to get sorted array.  Please let me know whether I doing something wrong? Or I missed anything ?

    You are having problem because you defined LLRQ_list to have 12 elements but only populated 5 elements.

    Sort will not work when you have empty elements.