Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andyiapan

macrumors newbie
Original poster
Feb 28, 2010
29
0
if i got number
123456
456786
232133
124456
143445

if i input 1,
it will search and display out 123456,124456,143445
if i input 12,
it will search and display out 123456,124456
if i keep on input 123,
it will search and display out 123456

how can i search like this?
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
Easy to be hard

I'm guessing you're asking for some low-level algorithm that compares your input to the array and returns the results you describe.

I'd take a different tack and use the instance methods in the NSArray class. The idea is that the Cocoa designers have already thought of most situations programmers would need and have created the appropriate methods.

Take a look at:
http://developer.apple.com/library/...Foundation/Classes/NSArray_Class/NSArray.html

probably start with one of the many indexOfObjectBlahBlah methods to see if they do what you want.
 

andyiapan

macrumors newbie
Original poster
Feb 28, 2010
29
0
Thanks ~~~;)

I'm guessing you're asking for some low-level algorithm that compares your input to the array and returns the results you describe.

I'd take a different tack and use the instance methods in the NSArray class. The idea is that the Cocoa designers have already thought of most situations programmers would need and have created the appropriate methods.

Take a look at:
http://developer.apple.com/library/...Foundation/Classes/NSArray_Class/NSArray.html

probably start with one of the many indexOfObjectBlahBlah methods to see if they do what you want.
 

andyiapan

macrumors newbie
Original poster
Feb 28, 2010
29
0
i can't found out using compare,
because of array value is not exactly same as compare value,

how can i use NSarray and integer value compare in that way><

Many Thanks

1 = 12344
1 = 1234455
1 = 13433
1 = 13333

13 = 13333
13 = 13433

134 = 13433
 

PatrickCocoa

macrumors 6502a
Dec 2, 2008
751
149
Swim in the Cocoa Sea

I agree with robbiedunan, who, as near as I can tell, is always right about everything.

It appears that your (andyiapan) issue is that you're:
1. Not familiar with Cocoa;
2. Not familiar with using pre-existing methods.

My advice is to use this current question as an opportunity to learn - open the NSArray documentation and just read through the various methods for 1/2 hour or an hour or until you get bored. Then do that a couple of times a day (expanding past NSArray to NSString or other classes) for a week or two.

Then the next time you have a question, instead of asking "what algorithm can I implement to get my answer", you'll ask "what methods are available that do what I want or almost what I want"?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.