View Full Version : Sort an Array or change Datatype from String to NSNumber

May 2, 2011, 04:07 AM
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 :o

May 2, 2011, 12:06 PM
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.