-2

I have to get min and max values from string array for example from this array (@"c 1", @"cc 22", @"h 123"), i want min-value=1 and max-value=123. I got the code from "How to get minimum & maximum value in a NSString/String array?" but unfortunately it is in Swift and I don't know Swift. I need the same code in Objective-C.

Community
  • 1
  • 1
Zeebok
  • 388
  • 1
  • 4
  • 15
  • 1
    You mean just the min max of the number parts of your strings? Or do letters represent some significance in what is higher/lower? – Kevin Oct 29 '15 at 08:37
  • You mean the shortest and longest string lengths? Do you need the index of these entries in the array or just the length? It's trivial code, so what have you tried? – trojanfoe Oct 29 '15 at 09:07
  • i don't know why my question is down-rated while my question was genuine. I searched on net and found code in swift while i don't know swift so what's the matter to ask for help to get code in objective-c. – Zeebok Oct 30 '15 at 07:59
  • this attitude is totally moral downing. . . think about it down-casters. – Zeebok Oct 30 '15 at 08:01
  • Your question is not understandable the way you posted it. It is missing information what to considder higher and lower values in your strings. The examples are not helping. Im voting to close, as it does not help others to understand your problem or why an answer might solve it. – Nikolai Ruhe Oct 31 '15 at 10:02
  • Mr.Nikiloi this forum is not only for experts. What should one do if he need help from experts and have little knowledge about problem. Experts like you should encourage such people to participate. Your attitude is not good to encourage people. – Zeebok Nov 17 '15 at 06:22

1 Answers1

0
NSArray *array = @[@"32e",@"asd32",@"34fa",@"asdf", @"234a", @"#"];
NSMutableArray *mArray = [[NSMutableArray alloc]init];
for (NSString *string in array) {
    NSMutableString *string1 = [[NSMutableString alloc]init];
    for (NSString *str in [string componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]) {
        [string1 appendString:str];
    }
    [mArray addObject:string1];
}

You can get an array that contains only numbers.Then, you can get min and max values easily.

Su Chou
  • 16
  • 1