Sort an Array or change Datatype from String to NSNumber

Discussion in 'iOS Programming' started by Nikke777, May 2, 2011.

  1. Nikke777, May 2, 2011
    Last edited by a moderator: May 2, 2011

    macrumors newbie

    May 2, 2011
    Hi there...

    I have got an array with numbers in it. These numbers are saved as a String.

    First I had them like "1", "5", ...
    Then I changed it to "001", "005", ...

    How can I sort that array the right way... The way I tried it does not give the right result. It is like: "001", "010", "011", "002", "003",... (the same without the leading zeros...)

    The other idea was to change the String to a int or double, but I dont know how to that... Is there a way to copy a array with changing all the entries by calling a function for every entrie like (doubleValue) ??

    Would prefer to sort the string array the right way.... :)

    Hope you guys can help me!



    finally got the change from string to nsnumber.. sorry for that.. but i cant figure out how to sort a string array with my content right...

    hopefully u guys can help me with that problem.

    cheers :eek:
  2. macrumors 68030


    Sep 2, 2008
    You need to use the NSNumericSearch comparison option to sort strings as numbers. You probably need to write a comparison function or block that compares using this option in order to sort an array.

Share This Page